-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an example of how to use SqsSubscription option
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
transformed-cfn-template.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" }' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |