Skip to content

Commit f36fd1a

Browse files
committed
Added an example of how to use SqsSubscription option
1 parent abd53c7 commit f36fd1a

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
transformed-cfn-template.yaml
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SNS-SQS Event Source Example
2+
3+
Example SAM template for processing messages on an SNS-SQS.
4+
5+
## Running the example
6+
7+
```bash
8+
# Set YOUR_S3_ARTIFACTS_BUCKET to a bucket you own
9+
YOUR_S3_ARTIFACTS_BUCKET='YOUR_S3_ARTIFACTS_BUCKET'; \
10+
aws cloudformation package --template-file template.yaml --output-template-file cfn-transformed-template.yaml --s3-bucket $YOUR_S3_ARTIFACTS_BUCKET
11+
aws cloudformation deploy --template-file ./cfn-transformed-template.yaml --stack-name lambda-sns-sqs-processor --capabilities CAPABILITY_IAM
12+
```
13+
14+
After your CloudFormation Stack has completed creation, send a message to the SNS topic to see it in action:
15+
16+
```bash
17+
YOUR_SNS_TOPIC_ARN=arn:aws:sns:us-east-1:[your_account_id]:[your_topic_name]; \
18+
aws sqs send-message --target-arn $YOUR_SNS_TOPIC_ARN --message '{ "myMessage": "Hello SAM!" }'
19+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
async function handler (event, context) {
2+
const records = event.Records
3+
console.log(records)
4+
return {}
5+
}
6+
7+
module.exports.handler = handler
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
Description: Example of processing messages on an SNS-SQS with Lambda
4+
Resources:
5+
MyTopic:
6+
Type: AWS::SNS::Topic
7+
MyFunction:
8+
Type: AWS::Serverless::Function
9+
Properties:
10+
CodeUri: ./index.js
11+
Handler: index.handler
12+
Runtime: nodejs8.10
13+
Events:
14+
MySQSEvent:
15+
Type: SNS
16+
Properties:
17+
Topic: !Ref MyTopic
18+
SqsSubscription: true
19+
20+
Outputs:
21+
MyTopic:
22+
Description: "MyTopic ARN"
23+
Value: !Ref MyTopic

0 commit comments

Comments
 (0)