Skip to content

Commit

Permalink
Added an example of how to use SqsSubscription option
Browse files Browse the repository at this point in the history
  • Loading branch information
53ningen committed Aug 25, 2019
1 parent abd53c7 commit f36fd1a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/2016-10-31/sns_sqs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
transformed-cfn-template.yaml
19 changes: 19 additions & 0 deletions examples/2016-10-31/sns_sqs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SNS-SQS Event Source Example

Example SAM template for processing messages on an SNS-SQS.

## Running the example

```bash
# Set YOUR_S3_ARTIFACTS_BUCKET to a bucket you own
YOUR_S3_ARTIFACTS_BUCKET='YOUR_S3_ARTIFACTS_BUCKET'; \
aws cloudformation package --template-file template.yaml --output-template-file cfn-transformed-template.yaml --s3-bucket $YOUR_S3_ARTIFACTS_BUCKET
aws cloudformation deploy --template-file ./cfn-transformed-template.yaml --stack-name lambda-sns-sqs-processor --capabilities CAPABILITY_IAM
```

After your CloudFormation Stack has completed creation, send a message to the SNS topic to see it in action:

```bash
YOUR_SNS_TOPIC_ARN=arn:aws:sns:us-east-1:[your_account_id]:[your_topic_name]; \
aws sqs send-message --target-arn $YOUR_SNS_TOPIC_ARN --message '{ "myMessage": "Hello SAM!" }'
```
7 changes: 7 additions & 0 deletions examples/2016-10-31/sns_sqs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
async function handler (event, context) {
const records = event.Records
console.log(records)
return {}
}

module.exports.handler = handler
23 changes: 23 additions & 0 deletions examples/2016-10-31/sns_sqs/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Example of processing messages on an SNS-SQS with Lambda
Resources:
MyTopic:
Type: AWS::SNS::Topic
MyFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./index.js
Handler: index.handler
Runtime: nodejs8.10
Events:
MySQSEvent:
Type: SNS
Properties:
Topic: !Ref MyTopic
SqsSubscription: true

Outputs:
MyTopic:
Description: "MyTopic ARN"
Value: !Ref MyTopic

0 comments on commit f36fd1a

Please sign in to comment.