Giter Site home page Giter Site logo

aws-serverless-sns-fanout's Introduction

AWS Serverless Amazon SNS Fanout Sample

The sample in this repository demonstrates how to implement the fanout messaging pattern to execute Lambda functions in two ways, using an AWS Lambda function and using an Amazon SNS published message.

Requirements

AWS Command Line Interface (CLI)

The examples are configured, packaged and deployed using the AWS Serverless Application Model (SAM). To use SAM, you must install and configure the AWS Command Line Interface (CLI). Please see the link below for more detail to install and configure the CLI:

Amazon S3 Bucket

The AWS Serverless Application Model (SAM) will be used to package the project in a zip archive and upload to S3 for deployment. Before using SAM, you must create an Amazon S3 bucket in the account and region that you will use for uploading artifacts, and configure it with permissions for access using the AWS credentials configured in the prior step. Please see the link below for more detail to create an Amazon S3 bucket:

Clone GitHub Repository

The examples below can be executed from a local workstation after cloning this Git repository locally. Please see the link below for more detail to clone the repository:

Instructions

Package and Deploy

Once this repository has been cloned, the sample can be packaged and deployed using the AWS CLI and SAM.

To package the project, execute the following command in the project directory, replacing S3_BUCKET with the Amazon S3 bucket that you created in the requirements setup. For more information on the CloudFormation Package command, please see this link.

aws cloudformation package --template-file template.yml --s3-bucket S3_BUCKET -artifacts --output-template-file output-template.yml

Once the package command has completed, the files in the directory will have been packaged into a zip archive, uploaded to the specified Amazon S3 bucket, and an output AWS CloudFormation template will be created with the S3 location of the archive.

The output AWS CloudFormation template is ready to be deployed using the following command. Please replace the following with values for your stack:

  • STACK_NAME with your custom stack name
  • S3_BUCKET_NAME with the name of the S3 Bucket to receive uploads for processing
  • SNS_TOPIC_NAME with the name of the SNS Topic for messaging publishing
aws cloudformation deploy --template-file output-template.yml --stack-name STACK_NAME --capabilities CAPABILITY_IAM --parameter-overrides S3BucketName=S3_BUCKET_NAME SnsTopicName=SNS_TOPIC_NAME

The S3 Bucket name and SNS Topic name must be specified and not generated to avoid a cyclical dependency when creating subscriptions, which is covered in more detail here: How do I avoid the error "Unable to validate the following destination configurations" when using S3 event notifications in CloudFormation?

Validate

Once the CloudFormation stack has been created, you can test both methods for fanout by uploading files to the S3 bucket using different S3 prefixes.

To test the Lambda fanout strategy:

  1. Use the S3 Bucket name when launching the stack and upload a file to the prefix /uploads/lambda/

  2. Navigate to the Lambda service in the AWS Console and confirm that the MediaInfoFunction, TranscodeAudioFunction, and FanoutFunction Lambda functions were successfully invoked.

To test the SNS fanout strategy:

  1. Use the S3 Bucket name when launching the stack and upload a file to the prefix /uploads/sns/.

  2. Navigate to the Lambda service in the AWS Console and confirm that the MediaInfoFunction and TranscodeAudioFunction Lambda functions were successfully invoked. The FanoutFunction Lambda function should not be invoked.

aws-serverless-sns-fanout's People

Contributors

jpeddicord avatar markatwood avatar samdengler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.