Split config into its own module
ADD
aws-js-sqs-slack/config.js
+// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
+
+let pulumi = require("@pulumi/pulumi");
+let config = new pulumi.Config(pulumi.getProject());
+module.exports = {
+ slackChannel: config.get("slackChannel") || "#general",
+ slackToken: config.require("slackToken"),
+};

MODIFY
aws-js-sqs-slack/index.js
aws-js-sqs-slack/index.js
-let pulumi = require("@pulumi/pulumi");
+// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
+
let aws = require("@pulumi/aws");
let serverless = require("@pulumi/aws-serverless");
-
-let config = new pulumi.Config(pulumi.getProject());
-let slackChannel = config.get("slackChannel") || "#general";
-let slackToken = config.require("slackToken");
+let config = require("./config");
let queue = new aws.sqs.Queue("mySlackQueue", { visibilityTimeoutSeconds: 180 });
serverless.queue.subscribe("mySlackPoster", queue, async (e) => {
let slack = require("@slack/client");
- let client = new slack.WebClient(slackToken);
+ let client = new slack.WebClient(config.slackToken);
for (let rec of e.Records) {
await client.chat.postMessage({
- channel: slackChannel,
+ channel: config.slackChannel,
text: `*SQS message ${rec.messageId}*:\n${rec.body}\n`+
`(with :love_letter: from Pulumi)`,
as_user: true,
});
- console.log(`Posted SQS message ${rec.messageId} to Slack channel ${slackChannel}`);
+ console.log(`Posted SQS message ${rec.messageId} to Slack channel ${config.slackChannel}`);
}
}, { batchSize: 1 });

Split config into its own module