Select your cookie preferences

We use cookies and similar tools to enhance your experience, provide our services, deliver relevant advertising, and make improvements. Approved third parties also use these tools to help us deliver advertising and provide certain site features.

Step Functions to SQS

Created with SnapStep FunctionsSQS

Create an AWS Step Functions workflow to integrate with Amazon SQS.

This CDK application deploys a Step Functions workflow, that takes in a payload and sends part of it to an Amazon SQS. In this pattern, the state machine does not wait for a callback from the queue. The application contains the minimum IAM resources required to run the workflow.

from aws_cdk import (
    Stack,
    Duration,
    CfnOutput,
    aws_stepfunctions as sfn,
    aws_sqs as sqs,
    aws_stepfunctions_tasks as sfn_tasks
)
from constructs import Construct

class SfnSqsCdkStack(Stack):

    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        my_queue = sqs.Queue(self, "queue-from-cdk")

        send_to_sqs_task = sfn_tasks.SqsSendMessage(self, id="SendToMyQueue",
                                                    message_body=sfn.TaskInput.
                                                    from_json_path_at("$.message")
                                                    , queue=my_queue)

        definition = send_to_sqs_task
        state_machine = sfn.StateMachine(
            self, "SQSWorkflowStateMachine",
            definition=definition,
            timeout=Duration.minutes(5)
        )


        CfnOutput(scope=self, id='StateMachineArn',
                       value=state_machine.state_machine_arn)
        CfnOutput(scope=self, id='QueueUrl',
                       value=my_queue.queue_url)

< Back to all patterns


GitHub icon Visit the GitHub repo for this pattern.

Download

git clone https://github.com/aws-samples/serverless-patterns/ cd serverless-patterns/sfn-sqs-cdk

Deploy

cdk deploy


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

1. Delete the stack: npx cdk destroy.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus".
3. You see a message confirming DELETE_COMPLETE.

Revanth Anireddy

Presented by Revanth Anireddy

Senior Cloud Applications Architect @ AWS.