Get more updates and further details about your project right in your mailbox.
The best time to establish protocols with your clients is when you onboard them.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.
AWS Lambda is an event-driven, server-less computing platform provided by Amazon. It is a fully server-less computing service that runs code in response to events and automatically manages the computing resources required.
Prerequisite for this article:
Before getting into the article you should have a basic idea about lambda and SQS in AWS. If you guys have no idea about those check out our previous articles to get an understanding about these services.
Things we are going to do:
Create a simple queue in SQS service by AWS
I have created a sample queue without any Dead Letter Queue and with all default settings provided by the AWS. To check how I have configured the Queue checkout my previous article: [AWS] Tutorial SQS (Simple Queue Service).
Create a lambda function with a log statement
Now lets go ahead and create a simple lambda function with just the console log statement.
I have a create a lambda function with node js environment.
So this is the code in the lambda function. It just logs the event received to the console. If you are not familiar with javascript environment you can use any other programming environment.
Adding SQS trigger to the Lambda and its configurations:
Before adding the trigger to the lambda kindly check the permissions of the lambda function. We have to provide the lambda permissions to access the SQS service. Go to configuration tab in your lambda function and click on the execution role and It will take you to IAM console where you can add the access.
As you can see the role has only one access that it to execute the lambda function. Click the Add permission and attach policies, it opens a window with list of many access policies as below.
Select any policy from the search bar. Type SQS in the search bar and select the AmazonSQSFullAccess policy and click the attach policy to add the access.
Now you can see there are 2 policies for our lambda role.
Lets add the SQS trigger for our lambda function. Click the add trigger option in the lambda function.
In trigger configuration:
Now you can see that the trigger has been setup for our lambda function.
Add message/data to the queue:
Now lets go ahead and start adding messages to the queue.
Check Cloudwatch logs of our Lambda function:
Go to cloudwatch from console. Click the logs and log groups and search for your lambda function and look into the log streams. (Note : You can see this directly from lambda too by checking the monitor tab in the lambda function).
As you can our log statement has printed the message that was received by our Lambda function.
And with that we have covered how we can setup our SQS as a trigger to our lambda function. My next article will be dealing with the dead letter queue with our current lambda function and handling the failed messages.