[{"data":1,"prerenderedAt":80},["ShallowReactive",2],{"pattern-sqs-lambda-eventbridge":3},{"id":4,"title":5,"architectureURL":6,"cleanup":7,"contributors":12,"deploy":14,"description":17,"extension":18,"framework":19,"gitHub":20,"highlight":6,"introBox":29,"language":35,"level":36,"meta":37,"patternArch":38,"resources":58,"s3URL":6,"services":70,"stem":71,"testing":72,"videoId":28,"__hash__":79},"patterns\u002Fpatterns\u002Fsqs-lambda-eventbridge.json","AWS Lambda polling Amazon SQS",null,{"headline":8,"text":9},"Cleanup",[10,11],"1. Delete the stack: \u003Ccode>cdk destroy\u003C\u002Fcode>.","2. Confirm the stack has been deleted: \u003Ccode>aws cloudformation list-stacks --query \"StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus\"\u003C\u002Fcode>",[13],"content\u002Fcontributors\u002Fcorneliu-croitoru.json",{"text":15},[16],"cdk deploy","Create a Lambda function that polls an SQS queue","json","AWS CDK",{"template":21,"payloads":26},{"projectFolder":22,"repoURL":23,"templateURL":24,"templateFile":25},"sqs-lambda-eb-cdk-python","https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-patterns\u002Ftree\u002Fmain\u002Fsqs-lambda-eb-cdk-python","serverless-patterns\u002Fsqs-lambda-eb-cdk-python","sqs_lambda_eb_cdk\u002Fsqs_lambda_eb_cdk_stack.py",[27],{"headline":28,"payloadURL":28},"",{"headline":30,"text":31},"How it works",[32,33,34],"This pattern deploys deploys a Lambda function, an SQS queue and an EventBridge rule.","The Lambda function is used control how many jobs to submit to a downstream service for each incoming message in an Amazon SQS queue. We may need to control the number of concurrent job executions due to a business requirement or due to scalability limitation of the downstream service. We are controlling the max number of concurrent executions by using a SQS queue. An Amazon EventBridge rule triggers an AWS Lambda function every 2 minutes to pick messages from SQS queue, one by one, until until we hit the max executions of our downstream service.","This does not use the SQS trigger for Lambda because the purpose is to slow down the creation of new executions. Whereas the Amazon SQS trigger would push messages to the AWS Lambda function more quickly.","Python","100",{},{"icon1":39,"icon2":44,"icon3":47,"line1":51,"line2":55},{"x":40,"y":41,"service":42,"label":43},20,50,"eventbridge","EventBridge",{"x":41,"y":41,"service":45,"label":46},"lambda","AWS Lambda",{"x":48,"y":41,"service":49,"label":50},80,"sqs","SQS",{"from":52,"to":53,"label":54},"icon1","icon2","Schedule",{"from":53,"to":56,"label":57},"icon3","Poll for messages",{"headline":59,"bullets":60},"Additional resources",[61,64,67],{"text":62,"link":63},"AWS CDK for Python workshop.","https:\u002F\u002Fcdkworkshop.com\u002F30-python.html",{"text":65,"link":66},"Choosing between messaging services for serverless applications.","https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Fchoosing-between-messaging-services-for-serverless-applications\u002F",{"text":68,"link":69},"Configuring a queue to trigger an AWS Lambda function","https:\u002F\u002Fdocs.aws.amazon.com\u002FAWSSimpleQueueService\u002Flatest\u002FSQSDeveloperGuide\u002Fsqs-configure-lambda-function-trigger.html",{"from":49,"to":45},"patterns\u002Fsqs-lambda-eventbridge",{"headline":73,"text":74},"Testing",[75,76,77,78],"Use the AWS CLI to send a message to the SQS queue and observe the event delivered to the Lambda function:","1. Delete the stack: \u003Ccode>sam delete --stack-name STACK_NAME\u003C\u002Fcode>.","1. Send several SQS messages by running this command multiple times: \u003Ccode>aws sqs send-message --queue-url ENTER_YOUR_SQS_QUEUE_URL --message-body \"Test message\"\u003C\u002Fcode>","2. Retrieve the logs from the Lambda function: \u003Ccode>aws logs describe-log-streams --log-group-name '\u002Faws\u002Flambda\u002FENTER_YOUR_FUNCTION_NAME' --query logStreams[*].logStreamName\u003C\u002Fcode>.","Qn0LwMIFvep6_EdttTrYoy1CmzNsXdSWJIDc9Qi3CsQ",1779273339799]