Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS SQS trigger Step Functions

Quick question: Is it possible to trigger the execution of a Step Function after an SQS message was sent?, if so, how would you specify it into the cloudformation yaml file?

Thanks in advance.

like image 334
Carlos Avatar asked Nov 22 '18 00:11

Carlos


People also ask

Can SQS trigger a step function?

Step Functions passes a message that includes a task token to an Amazon Simple Queue Service (Amazon SQS) queue. Step Functions then pauses, waiting for that token to be returned. The Amazon SQS queue triggers an Amazon Lambda function that calls SendTaskSuccess with that same task token.

Can SNS trigger Step Functions?

Unfortunately not SNS. You can invoke a StepFunction from: Lambda. API Gateway.

Can SQS trigger 2 lambdas?

You should not configure multiple Lambda functions as triggers for a single SQS queue. This is because the message in SQS will be delivered to any one consumer and while this message is being processed by that consumer, it would not be visible to others.


1 Answers

The first think to consider is this: do you really need to use SQS to start a Step Functions state machine? Can you use API gateway instead? Or could you write your messages to a S3 bucket and use the CloudWatch events to start a state machine?

If you must use SQS, then you will need to have a lambda function to act as a proxy. You will need to set up the queue as a lambda trigger, and you will need to write a lambda that can parse the SQS message and make the appropriate call to the Step Functions StartExecution API.

I’m on mobile, so I can’t type up the yaml right now, but if you need it, I can try to update with it later. For now, here is detailed walkthrough of how to invoke a Step Functions state machine from Lambda (including example yaml), and here is walkthrough of how to use CloudFormation to set up SQS to trigger a Lambda.

like image 118
Matthew Pope Avatar answered Oct 17 '22 21:10

Matthew Pope