AWS SQS with Lambda Trigger Step by Step Tutorial | Trigger Lambda when message in AWS SQS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back to my channel this is sambu from cloud Tech today I will show you like if you want to trigger Lambda function by using sqs then how we can configure like this Lambda with sqs that part today I'm going to demonstrate okay guys in my previous session I have already talked about how we can create a simple Q service and deep details about the simple Q service so if you guys not yet watch my previous video then I will request you guys please have a look at so that it will be easy to you to understand this session okay guys so I have already in AWS console and let's go to the simple Q service since I have already visited it is present here and if you didn't see here then you can search your sqs let's go to the simple Q service here and I have in my previous session I have created this uh sqs so this is my a q uh so this Q will send a message to this que then Lambda will take like what our agenda like whenever some message is coming to this Q then automatically Lambda function has to trigger okay guys so that is what our today agenda right so let's go to the Lambda okay so let's click on AWS Lambda here and let us create one Lambda function here I don't have any Lambda function so let's keep the demo okay guys and programming language like which you need as per your project requirement you could select that either Java Python and many programming language is there so as per your requirement you can select so for our today's demo let's select the python one okay and let's create this labda function okay guys so labda in progress to deep details about the Lambda I have talked about many time about this Lambda uh there are different kind of configuration all this thing so if you want to know more details about this Lambda then you can refer my previous like Lambda related videos and like step function all these things I have already demonstrated okay guys so you can refer that so this is my Lambda function here and let's keep this one as a default and so this Lambda has to trigger right when that message is coming this que then this Lambda has to trigger so for that what we need like if you go to the configuration section right and go to the permission tab here one IM Ro is created right so let's go to the IM Ro basically this IM Ro have only cloudwatch permission it's don't have that sqs permission basically okay so we need to add that sqs permission here so how we can add so let's go to the inline policy and then search here sqs so then we can search sqs food access read access execution Q access so let's for today's demo let's keep the full access here okay guys so the Lambda permission is done here and now let's go to the code part and Lambda has to trigger when when the Q message is coming right so this is the trigger PR so let's click on the Lambda triggers here and let's select here like Qs let's select here what the Q we have right this is the sqsq we have here and then here couple of option is there how many batch we get these all are optional if you want or if you have any requirement regarding this batch size batch processing all these things then you can modify as per your need okay guys but uh just keep in mind maximum is 10,000 for standard queue and 10 for F Q so this part just keep in mind okay these are the just here description is there if you need you just uh configure those things okay guys so let us just add that sqs here so our sqs addition is done here okay so this is our trigger and let's go to here and just print here like whatever message we are typing in that queue right that message we will print here okay let's try this print a and event event basically it say like what I can say it is a thing so we can print the record records okay and record is a string so we can keep like this and which position we want to like it's index of error right we can say like zero position and whatever message we are passing right that is nothing but the body actually okay so we can give like this okay or what the basically this event have cont like this message will have message ID and there are many other attributes right so to understand that let's give like this print event okay and then deploy the changes so our code is ready so let's come here q and just send some message okay manually just test it this is demo trigger with this Q something like that I'm giving this message and then just whenever I will click on send message this Lambda will get trigger how we came to know that part so let me show you that in here and just click on the cloud watch Matrix so this is my cloudwatch Matrix okay so let me check here this Lambda is R so here nothing is there in these log groups okay so once it is done right this log group will create so let's try this so send this message so message is sent here so hopefully this Lambda also will get triggered so see here this Lambda is tier this message is successfully delivered so hopefully this Lambda is tiered so let's go to the cloud watch and here this rule log group is created right so let's go here and if you go here you can see that so whatever that record right so that event whatever event we have printer right that is the records and message ID recipient Handler these are the things right qus message ID recipient Handler then we have like attributes we have start time stamp s Rider ID okay these are the many attribute we have here and also we have here region which region we sent right and from there we have print the record record is nothing but the body okay so let's see here what our message here like uh body and body part we have our message actual message right so that message I have printed here this is our print message the record so you can see that this is the hold event I have printed here and this is the actual message which I have typed in that sqs right so this message is printed here so this is how we can configure or we can integrate like AWS Lambda with sqs and this is how we can configure so I hope this we it's got clear so I will just quickly revise that what I have done in that IM role I need to attach that sqs because this this Lambda has to triggered by sqs right so sqs permission is required that's why I have attached this sqs Ro here and whenever this Lambda will trigger as we know automatically that cloud watch log group will create and in that log group we can see like we can debar like if any error is come right so let me show you that so suppose I am removing this permission okay uh let us try this one one more time okay try so this masses will not print it will give some error so let us try that this is not the case is not properly created let's try one one more time send just request here came here how come see right this is printed here permission let's try one more time so try message is didn't care sqs 2 right if you see here now sqs1 is there one is there but two is not it is not triggered why because this permission is not there right so let's if you add the permission here right then it will trigger automatically that two m also will come let me show you that yes and then add permission here then just refresh and now okay sess actually it is taking time looks like that whatever role we have added right so it is not quickly like it is affecting actually so it is taking some time to reflect here actually so this Ro is added now if you see right that another message came two also came here then three also will come just a minute is little slow actually because we are uh just changing permission all right so that's why it is taking time so now hopefully it will come three is came right if you see now this three messages started coming right so this is how we can integrate like Lambda with SQ so I hope this session will helpful to you guys how we can configure and if you feel this video is valuable then I will request you guys like this video and share surrounding with your friend and please subscribe my channel that will really Inspire to me to create this kind of video okay guys we'll see you in my next video sh bye
Info
Channel: CloudTech AWS & Azure & GCP for Everyone 🤝
Views: 43
Rating: undefined out of 5
Keywords: AWSCLOUD, AWSLAMBDA, EC2, ECR, ECS, DOCKER, S3, IAM, VPC, AWS SQS with Lambda Trigger Step by Step Tutorial, Trigger Lambda when message in AWS SQS, Trigger Lambda when there is a message in AWS SQS, How to Integrate AWS Lambda with AWS SQS, sqs, Simple Queue Service
Id: kWCL6xUcdys
Channel Id: undefined
Length: 14min 3sec (843 seconds)
Published: Sat Mar 09 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.