Publishing a message to the Amazon Simple Notification Service via AWS Console or AWS CLI to send a message to an SQS Queue as the subscription target and the Lambda Function will be triggered once it receives the event message from the SQS Queue.
-
Go to Amazon SNS → Topics → Your SNS Topic → Publish message
-
Enter the following information
a. Subject (optional)
b. Message body (see sample payload)
-
Click on the Publish message in the bottom right corner
-
Use the following command and replace the placeholder
sns_topic_arn
with the actual SNS Topic ARNaws sns publish \ --topic-arn sns_topic_arn \ --message file://sns-sample-message.json \ --subject "Cash on Delivery (COD) #210327LL6J2NE7"
The message comes from a JSON file and it will publish the specified message to the specified SNS Topic.
{
"referenceId": "210327LL6J2NE7",
"quantity": 1,
"item": [{
"id": "SMPLITM-12345",
"name": "Sample Item",
"price": 1234.50
}]
}
{
"log_code": "SQSEvent",
"log_msg": "Events from the SNS Topic -> SQS Queue",
"log_level": "INFO",
"log_keys": {
"record": {
"messageId": "a1234b5c-d6e7-8fa9-1b10-c1112def13ab",
"receiptHandle": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"body": "{\n \"Type\" : \"Notification\",\n \"MessageId\" : \"12a34567-bc89-10de-1f11-c2a13b14151\",\n \"TopicArn\" : \"arn:aws:sns:us-east-1:123456789101:sns-topic\",\n \"Subject\" : \"Cash on Delivery (COD) #210327LL6J2NE7\",\n \"Message\" : \"{\\n \\\"referenceId\\\": \\\"SMPLORDR-1234567890\\\",\\n \\\"quantity\\\": 1,\\n \\\"item\\\": [\\n {\\n \\\"id\\\": \\\"SMPLITM-12345\\\",\\n \\\"name\\\": \\\"Sample Item\\\",\\n \\\"price\\\": 1234.50\\n }\\n ]\\n}\",\n \"Timestamp\" : \"2023-05-23T09:05:09.617Z\",\n \"SignatureVersion\" : \"1\",\n \"Signature\" : \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\n \"SigningCertURL\" : \"https://sns.us-east-1.amazonaws.com/SimpleNotificationService-12a34567bc8910de1f11c2a13b141516.pem\",\n \"UnsubscribeURL\" : \"https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:123456789101:sns-topic:12a34567-bc89-10de-1f11-c2a13b14151\"\n}",
"md5OfBody": "12a34567bc8910de1f11c2a13b14151",
"md5OfMessageAttributes": "",
"attributes": {
"ApproximateFirstReceiveTimestamp": "1684832709676",
"ApproximateReceiveCount": "1",
"SenderId": "XXXXXXXXXXXXXXXXXXXXX",
"SentTimestamp": "1684832709668"
},
"messageAttributes": {},
"eventSourceARN": "arn:aws:sqs:us-east-1:123456789101:order-queue",
"eventSource": "aws:sqs",
"awsRegion": "us-east-1"
}
},
"log_timestamp": "2023-05-23 09:05:10"
}
- AWS Lambda
- AWS Lambda Event Sources
- Amazon Simple Queue Service
- Amazon Simple Notification Service
- Amazon Simple Notification Service Subscriptions
- Publish
- Subscribe
- Amazon SNS FAQs
- Email notifications
- Amazon Simple Notification Service endpoints and quotas
- Tutorial: Using AWS Lambda with Amazon Simple Notification Service
The cdk.json
file tells the CDK Toolkit how to execute your app.
npm install
install projects dependenciesnpm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation templatecdk bootstrap
deployment of AWS CloudFormation template to a specific AWS environment (account and region)cdk destroy
destroy this stack from your default AWS account/region
-
Install all the dependencies, bootstrap your project, and synthesized CloudFormation template.
# Without passing "profile" parameter dev@dev:~:aws-cdk-samples/sns/sns-sqs-subscription$ make init # With "profile" parameter dev@dev:~:aws-cdk-samples/sns/sns-sqs-subscription$ make init profile=[profile_name]
-
Deploy the project.
# Without passing "profile" parameter dev@dev:~:aws-cdk-samples/sns/sns-sqs-subscription$ make deploy # With "profile" parameter dev@dev:~:aws-cdk-samples/sns/sns-sqs-subscription$ make deploy profile=[profile_name]