Add an AWS SQS Lambda example
This adds a very simple example that posts to a Slack channel for every
SQS message, using an AWS Lambda.  New in 0.14.2!
ADD
aws-js-sqs-slack/.gitignore
+/bin/
+/node_modules/
+/.pulumi/

ADD
aws-js-sqs-slack/Pulumi.yaml
+name: aws-js-sqs-slack
+description: Post to Slack for each SQS message!
+runtime: nodejs

ADD
aws-js-sqs-slack/README.md
+# Post AWS SQS Messages to Slack using Serverless Lambdas
+
+This example wires up a serverless AWS Lambda to an AWS SQS queue and demonstrates posting a
+message to Slack. This program provisions resources using Pulumi's deployment system, but lets
+you write serverless code as ordinary JavaScript functions.
+
+## Prerequisites
+
+This program requires the Pulumi CLI. If you don't have it installed already,
+[get it here](https://pulumi.io/install) or simply run `curl -fsSL https://get.pulumi.com | sh`.
+
+After that, you'll need to [configure your AWS credentials](https://pulumi.io/install/aws.html) so that Pulumi can
+deploy into your account. If your AWS CLI is already configured, everything should just work.
+
+Since this example uses Slack, you'll also need
+[an access token](https://get.slack.help/hc/en-us/articles/215770388-Create-and-regenerate-API-tokens).
+
+## Running the Program
+
+After installing the CLI and cloning the repo, `cd` into the directory, and run these commands:
+
+1. Install NPM modules using `npm install` (or `yarn install` if you prefer Yarn).
+
+2. Create a new stack:
+
+ ```
+ $ pulumi stack init sqs-slack-dev
+ ```
+
+3. Configure the required variables:
+
+ ```
+ # Set the AWS region to deploy into:
+ $ pulumi config set aws:region us-west-2
+ # Configure the Slack channel and access token to use:
+ $ pulumi config set slackChannel "#general"
+ $ pulumi config set slackToken xoxb-123456789012-Xw937qtWSXJss1lFaKeqFAKE --secret
+ ```
+
+4. Deploy your program to AWS using the `pulumi update` command:
+
+ ```
+ $ pulumi update
+ ```
+
+ This command will show you the changes before it makes them. As soon as you select `yes`, it will begin
+ provisioning resources, uploading your lambda, etc. After it completes, your program is live!
+
+5. To test this out, push a message into your SQS queue using the AWS CLI:
+
+ ```
+ $ aws sqs send-message --queue-url $(pulumi stack output queueURL) --message-body "Pulumi+AWS rocks :boom:"
+ ```
+
+ If you've done everything right, you'll see a message posted to your Slack channel!
+
+ <img src="./sqs_slack.png" />
+
+ Notice we've used the `pulumi stack output` command to read the SQS queue URL that was provisioned.
+
+6. Run the `pulumi logs --follow` command to follow the logs. After a short while, you should see `console.log`
+ output that your message was posted to Slack.
+
+ ```
+ $ pulumi logs --follow
+ 2018-07-05T16:46:03.708-07:00[mySlackPoster-queue-subscripti] 2018-07-05T23:46:03.708Z 68b50931-a005-5e85-b5c4-5a890fee5519 Posted SQS message 3caa4069-f549-44d7-8534-6d61840d3420 to Slack channel #general
+ ```
+
+7. If you'd like to make some edits, try changing the `index.js` file, and then just run `pulumi update` again.
+ Pulumi will detect the minimal set of edits needed to deploy your code.
+
+8. After you're done playing around, you can destroy your program and stack by simply running two commands:
+
+ ```
+ $ pulumi destroy --yes
+ $ pulumi stack rm --yes
+ ```
+
+## Learning More
+
+To learn more about Pulumi, try checking out the [Tutorials](https://pulumi.io/quickstart) and
+[Tour](https://pulumi.io/tour) sections of [pulumi.io](https://pulumi.io).

ADD
aws-js-sqs-slack/index.js
+let pulumi = require("@pulumi/pulumi");
+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 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);
+ for (let rec of e.Records) {
+ await client.chat.postMessage({
+ channel: 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}`);
+ }
+}, { batchSize: 1 });
+
+module.exports = {
+ queueURL: queue.id,
+};

ADD
aws-js-sqs-slack/package.json
+{
+ "name": "aws-js-sqs-slack",
+ "dependencies": {
+ "@pulumi/aws": "latest",
+ "@pulumi/aws-serverless": "latest",
+ "@pulumi/pulumi": "latest",
+ "@slack/client": "^4.3.1"
+ }
+}

ADD
aws-js-sqs-slack/sqs_slack.png
aws-js-sqs-slack/sqs_slack.png
Binary files /dev/null and b/aws-js-sqs-slack/sqs_slack.png differ

Add an AWS SQS Lambda example

This adds a very simple example that posts to a Slack channel for every
SQS message, using an AWS Lambda.  New in @pulumi/aws 0.14.2!