Create a SQS in AWS and trigger a Lamdba function(AWS 中创建SQS,配置Lambda Trigger)
Follow the steps to create AWS SQS and trigger a Lambda function.
Purpose
To create a AWS SQS, then configure the queue to trigger a Lambda function.
And when you send a message in SQS, Lambda will recieve that message and print.
Steps
-
1. Create a queue and configure that queue.
-
Choose simple queue service in AWS, then click create queue.
Typing the queue name. - Change the access policy, let the lambda function have access to receive and send message from this queue, here is my needed policy ( Also, you can user the policy generator to generate policy that you needed). And other configuration can be default unless you need to change it. Then click create the queue button.
{
"Version": "2012-10-17",
"Id": "Policy1669600519451",
"Statement": [
{
"Sid": "Stmt1669600358052",
"Effect": "Allow",
"Principal": "*",
"Action": [
"sqs:DeleteMessage",
"sqs:GetQueueAttributes",
"sqs:ReceiveMessage"
],
"Resource": "arn:aws:sqs:ap-northeast-1:160071257600:firstQueue.fifo"
},
{
"Sid": "Stmt1669600517533",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::160071257600:root"
},
"Action": "sqs:*",
"Resource": "arn:aws:sqs:ap-northeast-1:160071257600:firstQueue.fifo"
}
]
}
-
2. Create a lambda function
-
Choose Lambda service in AWS. Click create function. And Typing the function name.
Choose a runtime Language, Node.js is used here. And the other settings can be default. Then click the create function button. That’s done.
3. Config lambda function trigger
-
choose the queue that you have created in step 1, click Lambda triggers, and then configure lambda function trigger.
Next, you need choose a lambda function that you wanted to triggered and save.
That’s about the setting up.
4. Send message to trigger lambda
-
In your created queue, there is a button called
send and receive message, click it and enter message that you want to send, then give it a fake message group ID and Message deduplication ID. That’s the way to seed message and trigger the lambda function.
5. Check the lambda function if it has been triggered
-
you can check your lambda function monitor in cloudWatch. By click the specific log stream, you can see the details of that event.
Also, you can change the display contents of this log event in lambda code source. And remember to deploy the changes
That’s all about how to create a SQS and configure a lambda trigger to receive the message that SQS send.