GithubHelp home page GithubHelp logo

subhamay-cloudworks / 0038-bellflower-cft Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 26 KB

Step Function with Callback Pattern Example (Amazon SQS, Amazon SNS, Lambda) using CloudFormation

Python 100.00%
aws-cloudformation aws-cloudwatch aws-cloudwatch-logs aws-iam aws-iam-policies aws-iam-roles aws-kms aws-lambda aws-python-lambda aws-sns aws-sqs aws-step-functions aws-s3-bucket

0038-bellflower-cft's Introduction

Project Bellflower : Step Function Callback Pattern Example (Amazon SQS, Amazon SNS, Lambda).

A State Machine demonstrating Lambda orchestration with a third party application using S3 and SQS and Lambda Callback functionality and notifying the users using SNS notification.

Description

This is demonstration of a State Machine with Lambda, SNS, SQS and S3. The processing Lambda generates a payload and pushes to a SQS Queue. An integration Lambda processes the payload and send a file with task token to S3 outbound folder. An Business Application processes the information and sends a success trigger to the S3 inbound folder. The integration Lambda reads the success trigger and sends a success signal to the State Machine and resumes processing. Once processing completes, the State Machine sends a Success notification to SNS Topic. If the processing Lambda fails after 3 retries the State Machine fails and a Failure notification is sent to the SNS Topic. The entire stack is created using CloudFormation.

Project Bellflower - Design Diagram

Project Bellflower - Services Used

Project Bellflower - State Machine

Getting Started

Dependencies

  • Create a Customer Managed KMS Key in the region where you want to create the stack.
  • Modify the KMS Key Policy to let the IAM user encrypt / decrypt using any resource using the created KMS Key. Following the kms-key-policy.json and use it after replacing the AWS Account Id.

Installing

  • Clone the repository https://github.com/subhamay-cloudworks/0038-bellflower-cft
  • Create a S3 bucket to store the CloudFormation nested stack templates and the Lambda code zip files.
  • Create the folders - bellflower/cft/nested-stacks, bellflower/cft/cross-stacks, bellflower/code/python, bellflower/cft/state-machine
  • Upload the following YAML templates to bellflower/cft/nested-stacks
    • iam-role-stack.yaml
    • lambda-function-stack.yaml
    • s3-stack.yaml
    • sns-stack.yaml
    • sqs-stack
    • cloudwatch-stack.yaml
  • Upload the following YAML templates to bellflower/cft/cross-stacks
    • custom-resource-lambda-stack.yaml
  • Zip and Upload the following Python files to bellflower/code/python
    • processing_lambda.py (processing_lambda.zip)
    • integration_lambda.py (integration_lambda.zip)
  • Upload the ASL file state-machine.asl.json to bellflower/cft/state-machine
  • Create the cross-stack using the template custom-resource-lambda-stack.yaml by using the S3 url and pass the appropriate parameters and note the cross stack name.
  • Create the entire stack by using the root stack template bellflower/cft/bellflower-root-stack.yaml and providing the required parameters and the s3 cross stack name created in the previous step.

Executing program

  • Execute the state machine with default payload. You can use the sample provided below:
{
    "Comment": "Bellflower - Callback Pattern Example (Amazon SQS, Amazon SNS, Lambda)"
}

Project Bellflower - Start Execution

Project Bellflower - Waiting for callback

  • Get the UUID of the execution from the log or from the S3 bucket outbound folder.
  • Create a success.json file in the bucket s3:///inbound//
  • Copy the success.json to S3 inbound folder
aws s3 cp success.json s3://<s3 bucket uri>/inbound/<UUID>/

Project Bellflower - Upload the success trigger to S3

Project Bellflower - State Machine Succeeds

Help

Post message in my blog (https://blog.subhamay.com)

Authors

Contributors names and contact info

Subhamay Bhattacharyya - [email protected]

Version History

  • 0.1
    • Initial Release

License

This project is licensed under Subhamay Bhattacharyya. All Rights Reserved.

Acknowledgments

AWS Documentation (https://docs.aws.amazon.com/step-functions/latest/dg/callback-task-sample-sqs.html)

0038-bellflower-cft's People

Contributors

subhamay-cloudworks avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.