All Projects → aws-samples → amazonmq-invoke-aws-lambda

aws-samples / amazonmq-invoke-aws-lambda

Licence: MIT-0 license
Demonstrates an approach to invoking AWS Lambda from messages in an Amazon MQ queue.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to amazonmq-invoke-aws-lambda

aws-sam-typescript-layers-example
Example project for developing AWS Lambda functions on TypeScript with all goodies: local development, tests, debugging, shared layers (3rd party and your own), and deploy.
Stars: ✭ 168 (+630.43%)
Mutual labels:  aws-sam, aws-lambda-node
Serverless Application Model
AWS Serverless Application Model (SAM) is an open-source framework for building serverless applications
Stars: ✭ 8,305 (+36008.7%)
Mutual labels:  aws-sam
lapa
Universal AWS Lambda packager
Stars: ✭ 20 (-13.04%)
Mutual labels:  aws-lambda-node
cfsec
Static analysis for CloudFormation templates to identify common misconfiguration
Stars: ✭ 53 (+130.43%)
Mutual labels:  aws-sam
lambda-watchtower
Serverless HTTP(S) Endpoint Monitoring With AWS Lambda & CloudWatch
Stars: ✭ 68 (+195.65%)
Mutual labels:  aws-lambda-node
aws-serverless-app-sam-cdk
Serverless app with CI/CD pipeline using AWS SAM and AWS CDK
Stars: ✭ 46 (+100%)
Mutual labels:  aws-sam
lambda-layer-canvas-nodejs
AWS Lambda Layer with node-canvas and its dependencies packaged, provides a Cairo backed Mozilla Web Canvas API implementation
Stars: ✭ 36 (+56.52%)
Mutual labels:  aws-lambda-node
ifto
A simple debugging module for AWS Lambda (λ) timeout
Stars: ✭ 72 (+213.04%)
Mutual labels:  aws-lambda-node
serverless-todo-demo
Todo app using AWS Serverless Application Model
Stars: ✭ 25 (+8.7%)
Mutual labels:  aws-sam
xilution-react-todomvc
An implementation of TodoMVC featuring AWS Serverless Application Model (SAM) and Xilution SaaS.
Stars: ✭ 24 (+4.35%)
Mutual labels:  aws-sam
elasticache-geospatial-public-bikes
Sample application that demonstrates use of Redis Geospatial commands using Amazon ElastiCache, AWS Lambda, and Serverless Application Model.
Stars: ✭ 34 (+47.83%)
Mutual labels:  aws-sam
swift-lambda-runtime
⚠️ Deprecated AWS Lambda Runtime - please use https://github.com/swift-server/swift-aws-lambda-runtime instead
Stars: ✭ 68 (+195.65%)
Mutual labels:  aws-sam
serverless-data-pipeline-sam
Serverless Data Pipeline powered by Kinesis Firehose, API Gateway, Lambda, S3, and Athena
Stars: ✭ 78 (+239.13%)
Mutual labels:  aws-sam
aws-appsync-session-manager
AWS AppSync Session Manager - a sample AppSync project
Stars: ✭ 18 (-21.74%)
Mutual labels:  aws-lambda-node
aws-vpc-flow-log-appender
Sample code to append additional information (e.g. Security Group IDs and geolocation data) to VPC Flow Logs for analysis in Elasticsearch.
Stars: ✭ 84 (+265.22%)
Mutual labels:  aws-sam
aws-sync-routes
Synchronizes the specified route from the main/default route table to all custom route tables in the VPC.
Stars: ✭ 16 (-30.43%)
Mutual labels:  aws-lambda-node
invoiceless
Serverless backend for sending simple recurring invoices
Stars: ✭ 44 (+91.3%)
Mutual labels:  aws-sam
serverless-discord-bot
A serverless Discord Bot template built for AWS Lambda based on Discord's slash commands and the slash-create library.
Stars: ✭ 37 (+60.87%)
Mutual labels:  aws-sam
iopipe-js
Build and run serverless apps with confidence on AWS Lambda with Tracing, Profiling, Metrics, Monitoring, and more.
Stars: ✭ 33 (+43.48%)
Mutual labels:  aws-lambda-node
faaskit
A lightweight middleware framework for functions as a service
Stars: ✭ 24 (+4.35%)
Mutual labels:  aws-sam

amazonmq-invoke-aws-lambda

This project is an example of one approach to invoking AWS Lambda from Queues and Topics managed by Amazon MQ brokers. This and other similar patterns can be useful in integrating legacy systems that leverage common APIs such as JMS with serverless architectures.

Our solution makes use of AWS CloudWatch Events to trigger a Lambda function that polls for messages on a queue. Messages are then sent to a second Lambda function that writes the message to an Amazon DynamoDB table. Further details can be found in our accompanying blog post.

Amazon MQ to Lambda Integration

Getting Started

To get started, clone this repository. The repository contains a CloudFormation template and source code to deploy and run the sample.

Prerequisites

To run the sample, you will need to:

  1. Select an AWS Region into which you will deploy services. Be sure that all required services (Amazon MQ, AWS Lambda, and Amazon DynamoDB) are available in the Region you select.
  2. Confirm your installation of the latest AWS CLI (at least version 1.14.2).
  3. Confirm the AWS CLI is properly configured with credentials that have administrator access to your AWS account.
  4. Install Node.js and NPM.

Deployment

We will deploy the solution in two parts, first a new Amazon MQ broker, then two sample Lambda functions and DynamoDB table.

Part 1: Amazon MQ Broker

Launching an Amazon MQ broker is easy via the Amazon MQ Console or AWS CLI. For details, see Creating and Configuring an Amazon MQ Broker.

Once the broker is ready, you will need to capture its Security Group ID(s) (e.g. "sg-12345678"). This information is available from the Amazon MQ Console or the AWS CLI as follows:

$ aws mq describe-broker --broker-id <MY_BROKER_ID> \
            --query 'SecurityGroups'

Part 2: Serverless

We will use the AWS Serverless Application Model to manage deployment of our EC2 instance, Lambda function, and other AWS resources:

  1. From the command line, create a new S3 Bucket from which to deploy our source code:

    $ aws s3 mb s3://<MY_BUCKET_NAME>
    
  2. Install Lambda dependencies:

    $ cd subscriber && npm install
    
    $ cd ../worker && npm install
    
    $ cd ..
    
  3. Using the Serverless Application Model, package the source code:

    $ aws cloudformation package --template-file template.yaml \
                --s3-bucket <MY_BUCKET_NAME> \
                --output-template-file packaged.yaml
    
  4. Next, deploy the CloudFormation stack, including the following parameters:

    • AmazonMQHost - your broker endpoint, e.g. <broker_id>.mq.us-east-2.amazonaws.com (note: do not incude the protocol or port)
    • AmazonMQLogin - username provided when creating your broker (e.g. master)
    • AmazonMQPassword - password provided when creating your broker
    • AmazonMQQueueName - name of your broker's queue, we use SAMPLE_QUEUE here
    • AmazonMQSecurityGroupId - security group id, as captured above (e.g. sg-12345678)
    $ aws cloudformation deploy --template-file packaged.yaml \
                --stack-name aws-amazonmq-sample \
                --capabilities CAPABILITY_IAM \
                --parameter-overrides AmazonMQHost=<AMAZONMQ_BROKER_ENDPOINT> \
                                      AmazonMQLogin=<AMAZONMQ_USERNAME> \
                                      AmazonMQPassword=<AMAZONMQ_PASSWORD> \
                                      AmazonMQQueueName=SAMPLE_QUEUE \
                                      AmazonMQSecurityGroupId=<SECURITY_GROUP_ID>
    
  5. It will take a few minutes for CloudFormation to finish deploying. Once status is CREATE_COMPLETE, move on to testing the integration.

Run!

Once the CloudFormation stack is complete, we can send a test message using the ActiveMQ console.

  1. Open the ActiveMQ Management Console, available at https://<BROKER_ENDPOINT>:8162. If you have trouble accessing the console, modify its security group to allow inbound traffic from your IP address.

  2. Click the link "Manage ActiveMQ broker" and enter the username and password from when you created the broker.

  3. In the menu just beneath the ActiveMQ logo, click the link at the far right, "Send".

  4. Modify two fields:

    • Destination: SAMPLE_QUEUE
    • Message body: Hello World, let's invoke Lambda!
  5. Click the Send button. Explore other aspects of the ActiveMQ console, particularly the Subscribers section, you should see one subscriber, your Flume instance.

  6. When ready, open the AWS Console and navigate to DynamoDB.

  7. Select "Tables" in the menu at left and then pick the table created by CloudFormation (name listed in CloudFormation Outputs).

  8. Select the "Items" tab and view items below. You should see an entry that contains the message from above.

Cleaning Up

Finally, we can clean up the environment using CloudFormation:

$ aws cloudformation delete-stack --stack-name aws-amazonmq-sample

As your Amazon MQ broker is not managed by CloudFormation, you will need to delete via the Console or CLI, if desired.

License Summary

This sample code is made available under a modified MIT license. See the LICENSE file.

Authors

  • jkahn - initial work
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].