Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History

README.md

Outline

Java AWS Lambda ActiveMQ (in private subnets) consumer, using AWS SAM

This pattern is an example of a Lambda function written in Java that consumes messages from Amazon MQ (Apache ActiveMQ), located in an private subnet. The function parses the ActiveMQ messages and stores the results in an Amazon DynamoDB table. The pattern provides an AWS CloudFormation template to install and set-up an Amazon MQ (Apache ActiveMQ) cluster inside private subnets in an Amazon VPC. The CloudFormation template also launches an Amazon EC2 instance with tools necessary to configure the Amazon MQ (Apache ActiveMQ) cluster and generate Amazon MQ (Apache ActiveMQ) messages.

This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders.

  • activemq_consumer_dynamo_sam/activemq_event_consumer_function/src/main/java - Code for the application's Lambda function that will listen for Amazon MQ (Apache ActiveMQ) messages and write them to an Amazon DynamoDB table
  • activemq_message_sender_json/src/main/java - Code for publishing messages with JSON payload into an Amazon MQ (ActiveMQ cluster)
  • activemq_consumer_dynamo_sam/template_original.yaml - A template that defines the application's Lambda function to be used by SAM to deploy the lambda function
  • ActiveMQAndClientEC2.yaml - An AWS CloudFormation template file that can be used to deploy an Amazon MQ (Apache ActiveMQ) cluster and also deploy an EC2 instance with all pre-requisities already installed, so you can directly build and deploy the lambda function and test it out.
  • activemq_queue_browser.sh - A shell script that can be used to connect to the Amazon MQ (Apache ActiveMQ) brokers using the activemq command-line tool

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

Requirements

  • Create an AWS account if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.

Run the AWS CloudFormation template to create the Amazon MQ (Apache ActiveMQ) Cluster and Client EC2 instance

  • [Run the AWS CloudFormation template using the file ActiveMQAndClientEC2.yaml] - You can go to the AWS CloudFormation console, create a new stack by specifying the template file. You can keep the defaults for input parameters or modify them as necessary. Wait for the AWS CloudFormation stack to be created. This AWS CloudFormation template will create an Amazon MQ (Apache ActiveMQ) cluster. It will also create an EC2 instance that you can use as a client.

  • [Connect to the EC2 instance] - Once the AWS CloudFormation stack is created, you can go to the EC2 console and log into the instance using either "Connect using EC2 Instance Connect" or "Connect using EC2 Instance Connect Endpoint" option under the "EC2 Instance Connect" tab. In case you are using SSM Instance connect, you are not initially placed in the home directory. If you connect as ssm-user, you need to sudo su to ec2-user for this to work. Note: You may need to wait for some time after the CloudFormation stack is created, as some UserData scripts continue running post creation.

Pre-requisites to Deploy the sample Lambda function

The EC2 instance created by the AWS CloudFormation template has all the software required to deploy the Lambda function.

The AWS SAM CLI is a serverless tool for building and testing Lambda applications.

We cloned the serverless-patterns Github repository on the EC2 instance already by running the below command git clone https://github.com/aws-samples/serverless-patterns.git Change directory to the pattern directory: cd serverless-patterns/activemq-private-lambda-java-sam

Use the SAM CLI to build and deploy the lambda function

Build your application with the sam build command.

cd activemq_consumer_dynamo_sam
sam build

The SAM CLI installs dependencies defined in activemq-private-lambda-java-sam/activemq_consumer_dynamo_sam/pom.xml, creates a deployment package, and saves it in the .aws-sam/build folder.

Test the build locally

Test a single function by invoking it directly with a test event. An event is a JSON document that represents the input that the function receives from the event source. Test events are included in the events folder in this project.

Run functions locally and invoke them with the sam local invoke command.

sam local invoke --event events/event.json

You should see a response such as the below:

***** Begin sam local invoke response *****

Begin Event *************{"eventSource":"aws:mq","eventSourceArn":"arn:aws:mq:us-west-2:123456789012:broker:ib-activemq-broker:b-aeb08c0d-6e46-412a-ad45-1507816242b0","messages":[{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:1","messageType":"jms/text-message","timestamp":1687328148384,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-1","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJKb3NlcGhpbmUiLCJsYXN0bmFtZSI6IkRhcmFrankiLCJjb21wYW55IjoiXCJDaGFuYXksIEplZmZyZXkgQSBFc3FcIiIsInN0cmVldCI6IjQgQiBCbHVlIFJpZGdlIEJsdmQiLCJjaXR5IjoiQnJpZ2h0b24iLCJjb3VudHkiOiJMaXZpbmdzdG9uIiwic3RhdGUiOiJNSSIsInppcCI6IjQ4MTE2IiwiaG9tZVBob25lIjoiODEwLTI5Mi05Mzg4IiwiY2VsbFBob25lIjoiODEwLTM3NC05ODQwIiwiZW1haWwiOiJqb3NlcGhpbmVfZGFyYWtqeUBkYXJha2p5Lm9yZyIsIndlYnNpdGUiOiJodHRwOi8vd3d3LmNoYW5heWplZmZyZXlhZXNxLmNvbSJ9","brokerInTime":1687328148385,"brokerOutTime":1687328148385},{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:38","messageType":"jms/text-message","timestamp":1687328148471,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-38","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJWYWxlbnRpbmUiLCJsYXN0bmFtZSI6IkdpbGxpYW4iLCJjb21wYW55IjoiRmJzIEJ1c2luZXNzIEZpbmFuY2UiLCJzdHJlZXQiOiI3NzUgVyAxN3RoIFN0IiwiY2l0eSI6IlNhbiBBbnRvbmlvIiwiY291bnR5IjoiQmV4YXIiLCJzdGF0ZSI6IlRYIiwiemlwIjoiNzgyMDQiLCJob21lUGhvbmUiOiIyMTAtODEyLTk1OTciLCJjZWxsUGhvbmUiOiIyMTAtMzAwLTYyNDQiLCJlbWFpbCI6InZhbGVudGluZV9naWxsaWFuQGdtYWlsLmNvbSIsIndlYnNpdGUiOiJodHRwOi8vd3d3LmZic2J1c2luZXNzZmluYW5jZS5jb20ifQ==","brokerInTime":1687328148472,"brokerOutTime":1687328148495},{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:48","messageType":"jms/text-message","timestamp":1687328148491,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-48","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJFbWVyc29uIiwibGFzdG5hbWUiOiJCb3dsZXkiLCJjb21wYW55IjoiS25pZ2h0cyBJbm4iLCJzdHJlZXQiOiI3NjIgUyBNYWluIFN0IiwiY2l0eSI6Ik1hZGlzb24iLCJjb3VudHkiOiJEYW5lIiwic3RhdGUiOiJXSSIsInppcCI6IjUzNzExIiwiaG9tZVBob25lIjoiNjA4LTMzNi03NDQ0IiwiY2VsbFBob25lIjoiNjA4LTY1OC03OTQwIiwiZW1haWwiOiJlbWVyc29uLmJvd2xleUBib3dsZXkub3JnIiwid2Vic2l0ZSI6Imh0dHA6Ly93d3cua25pZ2h0c2lubi5jb20ifQ==","brokerInTime":1687328148492,"brokerOutTime":1687328148534},{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:53","messageType":"jms/text-message","timestamp":1687328148498,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-53","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJNYXJqb3J5IiwibGFzdG5hbWUiOiJNYXN0ZWxsYSIsImNvbXBhbnkiOiJWaWNvbiBDb3Jwb3JhdGlvbiIsInN0cmVldCI6IjcxIFNhbiBNYXRlbyBBdmUiLCJjaXR5IjoiV2F5bmUiLCJjb3VudHkiOiJEZWxhd2FyZSIsInN0YXRlIjoiUEEiLCJ6aXAiOiIxOTA4NyIsImhvbWVQaG9uZSI6IjYxMC04MTQtNTUzMyIsImNlbGxQaG9uZSI6IjYxMC0zNzktNzEyNSIsImVtYWlsIjoibW1hc3RlbGxhQG1hc3RlbGxhLmNvbSIsIndlYnNpdGUiOiJodHRwOi8vd3d3LnZpY29uY29ycG9yYXRpb24uY29tIn0=","brokerInTime":1687328148503,"brokerOutTime":1687328148538},{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:58","messageType":"jms/text-message","timestamp":1687328148514,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-58","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJEZWxteSIsImxhc3RuYW1lIjoiQWhsZSIsImNvbXBhbnkiOiJXeWUgVGVjaG5vbG9naWVzIEluYyIsInN0cmVldCI6IjY1ODk1IFMgMTZ0aCBTdCIsImNpdHkiOiJQcm92aWRlbmNlIiwiY291bnR5IjoiUHJvdmlkZW5jZSIsInN0YXRlIjoiUkkiLCJ6aXAiOiIyOTA5IiwiaG9tZVBob25lIjoiNDAxLTQ1OC0yNTQ3IiwiY2VsbFBob25lIjoiNDAxLTU1OS04OTYxIiwiZW1haWwiOiJkZWxteS5haGxlQGhvdG1haWwuY29tIiwid2Vic2l0ZSI6Imh0dHA6Ly93d3cud3lldGVjaG5vbG9naWVzaW5jLmNvbSJ9","brokerInTime":1687328148514,"brokerOutTime":1687328148552},{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:63","messageType":"jms/text-message","timestamp":1687328148520,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-63","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJDYXJtZWxpbmEiLCJsYXN0bmFtZSI6IkxpbmRhbGwiLCJjb21wYW55IjoiR2VvcmdlIEplc3NvcCBDYXJ0ZXIgSmV3ZWxlcnMiLCJzdHJlZXQiOiIyNjY0IExld2lzIFJkIiwiY2l0eSI6IkxpdHRsZXRvbiIsImNvdW50eSI6IkRvdWdsYXMiLCJzdGF0ZSI6IkNPIiwiemlwIjoiODAxMjYiLCJob21lUGhvbmUiOiIzMDMtNzI0LTczNzEiLCJjZWxsUGhvbmUiOiIzMDMtODc0LTUxNjAiLCJlbWFpbCI6ImNhcm1lbGluYV9saW5kYWxsQGxpbmRhbGwuY29tIiwid2Vic2l0ZSI6Imh0dHA6Ly93d3cuZ2VvcmdlamVzc29wY2FydGVyamV3ZWxlcnMuY29tIn0=","brokerInTime":1687328148520,"brokerOutTime":1687328148556},{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:68","messageType":"jms/text-message","timestamp":1687328148526,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-68","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJJbGVuZSIsImxhc3RuYW1lIjoiRXJvbWFuIiwiY29tcGFueSI6IlwiUm9iaW5zb24sIFdpbGxpYW0gSiBFc3FcIiIsInN0cmVldCI6IjI4NTMgUyBDZW50cmFsIEV4cHkiLCJjaXR5IjoiR2xlbiBCdXJuaWUiLCJjb3VudHkiOiJBbm5lIEFydW5kZWwiLCJzdGF0ZSI6Ik1EIiwiemlwIjoiMjEwNjEiLCJob21lUGhvbmUiOiI0MTAtOTE0LTkwMTgiLCJjZWxsUGhvbmUiOiI0MTAtOTM3LTQ1NDMiLCJlbWFpbCI6ImlsZW5lLmVyb21hbkBob3RtYWlsLmNvbSIsIndlYnNpdGUiOiJodHRwOi8vd3d3LnJvYmluc29ud2lsbGlhbWplc3EuY29tIn0=","brokerInTime":1687328148527,"brokerOutTime":1687328148559},{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:75","messageType":"jms/text-message","timestamp":1687328148534,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-75","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJNb29uIiwibGFzdG5hbWUiOiJQYXJsYXRvIiwiY29tcGFueSI6IlwiQW1iZWxhbmcsIEplc3NpY2EgTSBNZFwiIiwic3RyZWV0IjoiNzQ5ODkgQnJhbmRvbiBTdCIsImNpdHkiOiJXZWxsc3ZpbGxlIiwiY291bnR5IjoiQWxsZWdhbnkiLCJzdGF0ZSI6Ik5ZIiwiemlwIjoiMTQ4OTUiLCJob21lUGhvbmUiOiI1ODUtODY2LTgzMTMiLCJjZWxsUGhvbmUiOiI1ODUtNDk4LTQyNzgiLCJlbWFpbCI6Im1vb25AeWFob28uY29tIiwid2Vic2l0ZSI6Imh0dHA6Ly93d3cuYW1iZWxhbmdqZXNzaWNhbW1kLmNvbSJ9","brokerInTime":1687328148534,"brokerOutTime":1687328148574},{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:78","messageType":"jms/text-message","timestamp":1687328148537,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-78","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJWaXZhIiwibGFzdG5hbWUiOiJUb2Vsa2VzIiwiY29tcGFueSI6Ik1hcmsgSXYgUHJlc3MgTHRkIiwic3RyZWV0IjoiNDI4NCBEb3JpZ28gTG4iLCJjaXR5IjoiQ2hpY2FnbyIsImNvdW50eSI6IkNvb2siLCJzdGF0ZSI6IklMIiwiemlwIjoiNjA2NDciLCJob21lUGhvbmUiOiI3NzMtNDQ2LTU1NjkiLCJjZWxsUGhvbmUiOiI3NzMtMzUyLTM0MzciLCJlbWFpbCI6InZpdmEudG9lbGtlc0BnbWFpbC5jb20iLCJ3ZWJzaXRlIjoiaHR0cDovL3d3dy5tYXJraXZwcmVzc2x0ZC5jb20ifQ==","brokerInTime":1687328148538,"brokerOutTime":1687328148576},{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:81","messageType":"jms/text-message","timestamp":1687328148540,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-81","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJUaW1vdGh5IiwibGFzdG5hbWUiOiJNdWxxdWVlbiIsImNvbXBhbnkiOiJTYXJvbml4IE55bXBoIFByb2R1Y3RzIiwic3RyZWV0IjoiNDQgVyA0dGggU3QiLCJjaXR5IjoiU3RhdGVuIElzbGFuZCIsImNvdW50eSI6IlJpY2htb25kIiwic3RhdGUiOiJOWSIsInppcCI6IjEwMzA5IiwiaG9tZVBob25lIjoiNzE4LTMzMi02NTI3IiwiY2VsbFBob25lIjoiNzE4LTY1NC03MDYzIiwiZW1haWwiOiJ0aW1vdGh5X211bHF1ZWVuQG11bHF1ZWVuLm9yZyIsIndlYnNpdGUiOiJodHRwOi8vd3d3LnNhcm9uaXhueW1waHByb2R1Y3RzLmNvbSJ9","brokerInTime":1687328148541,"brokerOutTime":1687328148578}]}End Event ***************Begin Message *************{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:1","messageType":"jms/text-message","timestamp":1687328148384,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-1","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJKb3NlcGhpbmUiLCJsYXN0bmFtZSI6IkRhcmFrankiLCJjb21wYW55IjoiXCJDaGFuYXksIEplZmZyZXkgQSBFc3FcIiIsInN0cmVldCI6IjQgQiBCbHVlIFJpZGdlIEJsdmQiLCJjaXR5IjoiQnJpZ2h0b24iLCJjb3VudHkiOiJMaXZpbmdzdG9uIiwic3RhdGUiOiJNSSIsInppcCI6IjQ4MTE2IiwiaG9tZVBob25lIjoiODEwLTI5Mi05Mzg4IiwiY2VsbFBob25lIjoiODEwLTM3NC05ODQwIiwiZW1haWwiOiJqb3NlcGhpbmVfZGFyYWtqeUBkYXJha2p5Lm9yZyIsIndlYnNpdGUiOiJodHRwOi8vd3d3LmNoYW5heWplZmZyZXlhZXNxLmNvbSJ9","brokerInTime":1687328148385,"brokerOutTime":1687328148385}End Message ***************Begin Message Body *************{"firstname":"Josephine","lastname":"Darakjy","company":"\"Chanay, Jeffrey A Esq\"","street":"4 B Blue Ridge Blvd","city":"Brighton","county":"Livingston","state":"MI","zip":"48116","homePhone":"810-292-9388","cellPhone":"810-374-9840","email":"josephine_darakjy@darakjy.org","website":"http://www.chanayjeffreyaesq.com"}End Message Body ***************EventSource = aws:mqEventSourceARN = arn:aws:mq:us-west-2:123456789012:broker:ib-activemq-broker:b-aeb08c0d-6e46-412a-ad45-1507816242b0CorrelationID = TestMessage07-06-21-2023-06-06-02-1MessageID = ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:1MessageType = jms/text-messageReplyTo = nullType = TextMessageBrokerInTime = 1687328148385BrokerOutTime = 1687328148385DeliveryMode = 1Expiration = 0Priority = 4TimeStamp = 1687328148384Queue = LambdaActiveMQQueueWhetherRedelivered = falseThis person = {"firstname":"Josephine","lastname":"Darakjy","company":"\"Chanay, Jeffrey A Esq\"","street":"4 B Blue Ridge Blvd","city":"Brighton","county":"Livingston","state":"MI","zip":"48116","homePhone":"810-292-9388","cellPhone":"810-374-9840","email":"josephine_darakjy@darakjy.org","website":"http://www.chanayjeffreyaesq.com"}Begin Message *************{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:38","messageType":"jms/text-message","timestamp":1687328148471,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-38","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJWYWxlbnRpbmUiLCJsYXN0bmFtZSI6IkdpbGxpYW4iLCJjb21wYW55IjoiRmJzIEJ1c2luZXNzIEZpbmFuY2UiLCJzdHJlZXQiOiI3NzUgVyAxN3RoIFN0IiwiY2l0eSI6IlNhbiBBbnRvbmlvIiwiY291bnR5IjoiQmV4YXIiLCJzdGF0ZSI6IlRYIiwiemlwIjoiNzgyMDQiLCJob21lUGhvbmUiOiIyMTAtODEyLTk1OTciLCJjZWxsUGhvbmUiOiIyMTAtMzAwLTYyNDQiLCJlbWFpbCI6InZhbGVudGluZV9naWxsaWFuQGdtYWlsLmNvbSIsIndlYnNpdGUiOiJodHRwOi8vd3d3LmZic2J1c2luZXNzZmluYW5jZS5jb20ifQ==","brokerInTime":1687328148472,"brokerOutTime":1687328148495}End Message ***************Begin Message Body *************{"firstname":"Valentine","lastname":"Gillian","company":"Fbs Business Finance","street":"775 W 17th St","city":"San Antonio","county":"Bexar","state":"TX","zip":"78204","homePhone":"210-812-9597","cellPhone":"210-300-6244","email":"valentine_gillian@gmail.com","website":"http://www.fbsbusinessfinance.com"}End Message Body ***************EventSource = aws:mqEventSourceARN = arn:aws:mq:us-west-2:123456789012:broker:ib-activemq-broker:b-aeb08c0d-6e46-412a-ad45-1507816242b0CorrelationID = TestMessage07-06-21-2023-06-06-02-38MessageID = ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:38MessageType = jms/text-messageReplyTo = nullType = TextMessageBrokerInTime = 1687328148472BrokerOutTime = 1687328148495DeliveryMode = 1Expiration = 0Priority = 4TimeStamp = 1687328148471Queue = LambdaActiveMQQueueWhetherRedelivered = falseThis person = {"firstname":"Valentine","lastname":"Gillian","company":"Fbs Business Finance","street":"775 W 17th St","city":"San Antonio","county":"Bexar","state":"TX","zip":"78204","homePhone":"210-812-9597","cellPhone":"210-300-6244","email":"valentine_gillian@gmail.com","website":"http://www.fbsbusinessfinance.com"}Begin Message *************{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:48","messageType":"jms/text-message","timestamp":1687328148491,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-48","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJFbWVyc29uIiwibGFzdG5hbWUiOiJCb3dsZXkiLCJjb21wYW55IjoiS25pZ2h0cyBJbm4iLCJzdHJlZXQiOiI3NjIgUyBNYWluIFN0IiwiY2l0eSI6Ik1hZGlzb24iLCJjb3VudHkiOiJEYW5lIiwic3RhdGUiOiJXSSIsInppcCI6IjUzNzExIiwiaG9tZVBob25lIjoiNjA4LTMzNi03NDQ0IiwiY2VsbFBob25lIjoiNjA4LTY1OC03OTQwIiwiZW1haWwiOiJlbWVyc29uLmJvd2xleUBib3dsZXkub3JnIiwid2Vic2l0ZSI6Imh0dHA6Ly93d3cua25pZ2h0c2lubi5jb20ifQ==","brokerInTime":1687328148492,"brokerOutTime":1687328148534}End Message ***************Begin Message Body *************{"firstname":"Emerson","lastname":"Bowley","company":"Knights Inn","street":"762 S Main St","city":"Madison","county":"Dane","state":"WI","zip":"53711","homePhone":"608-336-7444","cellPhone":"608-658-7940","email":"emerson.bowley@bowley.org","website":"http://www.knightsinn.com"}End Message Body ***************EventSource = aws:mqEventSourceARN = arn:aws:mq:us-west-2:123456789012:broker:ib-activemq-broker:b-aeb08c0d-6e46-412a-ad45-1507816242b0CorrelationID = TestMessage07-06-21-2023-06-06-02-48MessageID = ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:48MessageType = jms/text-messageReplyTo = nullType = TextMessageBrokerInTime = 1687328148492BrokerOutTime = 1687328148534DeliveryMode = 1Expiration = 0Priority = 4TimeStamp = 1687328148491Queue = LambdaActiveMQQueueWhetherRedelivered = falseThis person = {"firstname":"Emerson","lastname":"Bowley","company":"Knights Inn","street":"762 S Main St","city":"Madison","county":"Dane","state":"WI","zip":"53711","homePhone":"608-336-7444","cellPhone":"608-658-7940","email":"emerson.bowley@bowley.org","website":"http://www.knightsinn.com"}Begin Message *************{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:53","messageType":"jms/text-message","timestamp":1687328148498,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-53","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJNYXJqb3J5IiwibGFzdG5hbWUiOiJNYXN0ZWxsYSIsImNvbXBhbnkiOiJWaWNvbiBDb3Jwb3JhdGlvbiIsInN0cmVldCI6IjcxIFNhbiBNYXRlbyBBdmUiLCJjaXR5IjoiV2F5bmUiLCJjb3VudHkiOiJEZWxhd2FyZSIsInN0YXRlIjoiUEEiLCJ6aXAiOiIxOTA4NyIsImhvbWVQaG9uZSI6IjYxMC04MTQtNTUzMyIsImNlbGxQaG9uZSI6IjYxMC0zNzktNzEyNSIsImVtYWlsIjoibW1hc3RlbGxhQG1hc3RlbGxhLmNvbSIsIndlYnNpdGUiOiJodHRwOi8vd3d3LnZpY29uY29ycG9yYXRpb24uY29tIn0=","brokerInTime":1687328148503,"brokerOutTime":1687328148538}End Message ***************Begin Message Body *************{"firstname":"Marjory","lastname":"Mastella","company":"Vicon Corporation","street":"71 San Mateo Ave","city":"Wayne","county":"Delaware","state":"PA","zip":"19087","homePhone":"610-814-5533","cellPhone":"610-379-7125","email":"mmastella@mastella.com","website":"http://www.viconcorporation.com"}End Message Body ***************EventSource = aws:mqEventSourceARN = arn:aws:mq:us-west-2:123456789012:broker:ib-activemq-broker:b-aeb08c0d-6e46-412a-ad45-1507816242b0CorrelationID = TestMessage07-06-21-2023-06-06-02-53MessageID = ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:53MessageType = jms/text-messageReplyTo = nullType = TextMessageBrokerInTime = 1687328148503BrokerOutTime = 1687328148538DeliveryMode = 1Expiration = 0Priority = 4TimeStamp = 1687328148498Queue = LambdaActiveMQQueueWhetherRedelivered = falseThis person = {"firstname":"Marjory","lastname":"Mastella","company":"Vicon Corporation","street":"71 San Mateo Ave","city":"Wayne","county":"Delaware","state":"PA","zip":"19087","homePhone":"610-814-5533","cellPhone":"610-379-7125","email":"mmastella@mastella.com","website":"http://www.viconcorporation.com"}Begin Message *************{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:58","messageType":"jms/text-message","timestamp":1687328148514,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-58","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJEZWxteSIsImxhc3RuYW1lIjoiQWhsZSIsImNvbXBhbnkiOiJXeWUgVGVjaG5vbG9naWVzIEluYyIsInN0cmVldCI6IjY1ODk1IFMgMTZ0aCBTdCIsImNpdHkiOiJQcm92aWRlbmNlIiwiY291bnR5IjoiUHJvdmlkZW5jZSIsInN0YXRlIjoiUkkiLCJ6aXAiOiIyOTA5IiwiaG9tZVBob25lIjoiNDAxLTQ1OC0yNTQ3IiwiY2VsbFBob25lIjoiNDAxLTU1OS04OTYxIiwiZW1haWwiOiJkZWxteS5haGxlQGhvdG1haWwuY29tIiwid2Vic2l0ZSI6Imh0dHA6Ly93d3cud3lldGVjaG5vbG9naWVzaW5jLmNvbSJ9","brokerInTime":1687328148514,"brokerOutTime":1687328148552}End Message ***************Begin Message Body *************{"firstname":"Delmy","lastname":"Ahle","company":"Wye Technologies Inc","street":"65895 S 16th St","city":"Providence","county":"Providence","state":"RI","zip":"2909","homePhone":"401-458-2547","cellPhone":"401-559-8961","email":"delmy.ahle@hotmail.com","website":"http://www.wyetechnologiesinc.com"}End Message Body ***************EventSource = aws:mqEventSourceARN = arn:aws:mq:us-west-2:123456789012:broker:ib-activemq-broker:b-aeb08c0d-6e46-412a-ad45-1507816242b0CorrelationID = TestMessage07-06-21-2023-06-06-02-58MessageID = ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:58MessageType = jms/text-messageReplyTo = nullType = TextMessageBrokerInTime = 1687328148514BrokerOutTime = 1687328148552DeliveryMode = 1Expiration = 0Priority = 4TimeStamp = 1687328148514Queue = LambdaActiveMQQueueWhetherRedelivered = falseThis person = {"firstname":"Delmy","lastname":"Ahle","company":"Wye Technologies Inc","street":"65895 S 16th St","city":"Providence","county":"Providence","state":"RI","zip":"2909","homePhone":"401-458-2547","cellPhone":"401-559-8961","email":"delmy.ahle@hotmail.com","website":"http://www.wyetechnologiesinc.com"}Begin Message *************{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:63","messageType":"jms/text-message","timestamp":1687328148520,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-63","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJDYXJtZWxpbmEiLCJsYXN0bmFtZSI6IkxpbmRhbGwiLCJjb21wYW55IjoiR2VvcmdlIEplc3NvcCBDYXJ0ZXIgSmV3ZWxlcnMiLCJzdHJlZXQiOiIyNjY0IExld2lzIFJkIiwiY2l0eSI6IkxpdHRsZXRvbiIsImNvdW50eSI6IkRvdWdsYXMiLCJzdGF0ZSI6IkNPIiwiemlwIjoiODAxMjYiLCJob21lUGhvbmUiOiIzMDMtNzI0LTczNzEiLCJjZWxsUGhvbmUiOiIzMDMtODc0LTUxNjAiLCJlbWFpbCI6ImNhcm1lbGluYV9saW5kYWxsQGxpbmRhbGwuY29tIiwid2Vic2l0ZSI6Imh0dHA6Ly93d3cuZ2VvcmdlamVzc29wY2FydGVyamV3ZWxlcnMuY29tIn0=","brokerInTime":1687328148520,"brokerOutTime":1687328148556}End Message ***************Begin Message Body *************{"firstname":"Carmelina","lastname":"Lindall","company":"George Jessop Carter Jewelers","street":"2664 Lewis Rd","city":"Littleton","county":"Douglas","state":"CO","zip":"80126","homePhone":"303-724-7371","cellPhone":"303-874-5160","email":"carmelina_lindall@lindall.com","website":"http://www.georgejessopcarterjewelers.com"}End Message Body ***************EventSource = aws:mqEventSourceARN = arn:aws:mq:us-west-2:123456789012:broker:ib-activemq-broker:b-aeb08c0d-6e46-412a-ad45-1507816242b0CorrelationID = TestMessage07-06-21-2023-06-06-02-63MessageID = ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:63MessageType = jms/text-messageReplyTo = nullType = TextMessageBrokerInTime = 1687328148520BrokerOutTime = 1687328148556DeliveryMode = 1Expiration = 0Priority = 4TimeStamp = 1687328148520Queue = LambdaActiveMQQueueWhetherRedelivered = falseThis person = {"firstname":"Carmelina","lastname":"Lindall","company":"George Jessop Carter Jewelers","street":"2664 Lewis Rd","city":"Littleton","county":"Douglas","state":"CO","zip":"80126","homePhone":"303-724-7371","cellPhone":"303-874-5160","email":"carmelina_lindall@lindall.com","website":"http://www.georgejessopcarterjewelers.com"}Begin Message *************{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:68","messageType":"jms/text-message","timestamp":1687328148526,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-68","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJJbGVuZSIsImxhc3RuYW1lIjoiRXJvbWFuIiwiY29tcGFueSI6IlwiUm9iaW5zb24sIFdpbGxpYW0gSiBFc3FcIiIsInN0cmVldCI6IjI4NTMgUyBDZW50cmFsIEV4cHkiLCJjaXR5IjoiR2xlbiBCdXJuaWUiLCJjb3VudHkiOiJBbm5lIEFydW5kZWwiLCJzdGF0ZSI6Ik1EIiwiemlwIjoiMjEwNjEiLCJob21lUGhvbmUiOiI0MTAtOTE0LTkwMTgiLCJjZWxsUGhvbmUiOiI0MTAtOTM3LTQ1NDMiLCJlbWFpbCI6ImlsZW5lLmVyb21hbkBob3RtYWlsLmNvbSIsIndlYnNpdGUiOiJodHRwOi8vd3d3LnJvYmluc29ud2lsbGlhbWplc3EuY29tIn0=","brokerInTime":1687328148527,"brokerOutTime":1687328148559}End Message ***************Begin Message Body *************{"firstname":"Ilene","lastname":"Eroman","company":"\"Robinson, William J Esq\"","street":"2853 S Central Expy","city":"Glen Burnie","county":"Anne Arundel","state":"MD","zip":"21061","homePhone":"410-914-9018","cellPhone":"410-937-4543","email":"ilene.eroman@hotmail.com","website":"http://www.robinsonwilliamjesq.com"}End Message Body ***************EventSource = aws:mqEventSourceARN = arn:aws:mq:us-west-2:123456789012:broker:ib-activemq-broker:b-aeb08c0d-6e46-412a-ad45-1507816242b0CorrelationID = TestMessage07-06-21-2023-06-06-02-68MessageID = ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:68MessageType = jms/text-messageReplyTo = nullType = TextMessageBrokerInTime = 1687328148527BrokerOutTime = 1687328148559DeliveryMode = 1Expiration = 0Priority = 4TimeStamp = 1687328148526Queue = LambdaActiveMQQueueWhetherRedelivered = falseThis person = {"firstname":"Ilene","lastname":"Eroman","company":"\"Robinson, William J Esq\"","street":"2853 S Central Expy","city":"Glen Burnie","county":"Anne Arundel","state":"MD","zip":"21061","homePhone":"410-914-9018","cellPhone":"410-937-4543","email":"ilene.eroman@hotmail.com","website":"http://www.robinsonwilliamjesq.com"}Begin Message *************{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:75","messageType":"jms/text-message","timestamp":1687328148534,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-75","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJNb29uIiwibGFzdG5hbWUiOiJQYXJsYXRvIiwiY29tcGFueSI6IlwiQW1iZWxhbmcsIEplc3NpY2EgTSBNZFwiIiwic3RyZWV0IjoiNzQ5ODkgQnJhbmRvbiBTdCIsImNpdHkiOiJXZWxsc3ZpbGxlIiwiY291bnR5IjoiQWxsZWdhbnkiLCJzdGF0ZSI6Ik5ZIiwiemlwIjoiMTQ4OTUiLCJob21lUGhvbmUiOiI1ODUtODY2LTgzMTMiLCJjZWxsUGhvbmUiOiI1ODUtNDk4LTQyNzgiLCJlbWFpbCI6Im1vb25AeWFob28uY29tIiwid2Vic2l0ZSI6Imh0dHA6Ly93d3cuYW1iZWxhbmdqZXNzaWNhbW1kLmNvbSJ9","brokerInTime":1687328148534,"brokerOutTime":1687328148574}End Message ***************Begin Message Body *************{"firstname":"Moon","lastname":"Parlato","company":"\"Ambelang, Jessica M Md\"","street":"74989 Brandon St","city":"Wellsville","county":"Allegany","state":"NY","zip":"14895","homePhone":"585-866-8313","cellPhone":"585-498-4278","email":"moon@yahoo.com","website":"http://www.ambelangjessicammd.com"}End Message Body ***************EventSource = aws:mqEventSourceARN = arn:aws:mq:us-west-2:123456789012:broker:ib-activemq-broker:b-aeb08c0d-6e46-412a-ad45-1507816242b0CorrelationID = TestMessage07-06-21-2023-06-06-02-75MessageID = ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:75MessageType = jms/text-messageReplyTo = nullType = TextMessageBrokerInTime = 1687328148534BrokerOutTime = 1687328148574DeliveryMode = 1Expiration = 0Priority = 4TimeStamp = 1687328148534Queue = LambdaActiveMQQueueWhetherRedelivered = falseThis person = {"firstname":"Moon","lastname":"Parlato","company":"\"Ambelang, Jessica M Md\"","street":"74989 Brandon St","city":"Wellsville","county":"Allegany","state":"NY","zip":"14895","homePhone":"585-866-8313","cellPhone":"585-498-4278","email":"moon@yahoo.com","website":"http://www.ambelangjessicammd.com"}Begin Message *************{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:78","messageType":"jms/text-message","timestamp":1687328148537,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-78","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJWaXZhIiwibGFzdG5hbWUiOiJUb2Vsa2VzIiwiY29tcGFueSI6Ik1hcmsgSXYgUHJlc3MgTHRkIiwic3RyZWV0IjoiNDI4NCBEb3JpZ28gTG4iLCJjaXR5IjoiQ2hpY2FnbyIsImNvdW50eSI6IkNvb2siLCJzdGF0ZSI6IklMIiwiemlwIjoiNjA2NDciLCJob21lUGhvbmUiOiI3NzMtNDQ2LTU1NjkiLCJjZWxsUGhvbmUiOiI3NzMtMzUyLTM0MzciLCJlbWFpbCI6InZpdmEudG9lbGtlc0BnbWFpbC5jb20iLCJ3ZWJzaXRlIjoiaHR0cDovL3d3dy5tYXJraXZwcmVzc2x0ZC5jb20ifQ==","brokerInTime":1687328148538,"brokerOutTime":1687328148576}End Message ***************Begin Message Body *************{"firstname":"Viva","lastname":"Toelkes","company":"Mark Iv Press Ltd","street":"4284 Dorigo Ln","city":"Chicago","county":"Cook","state":"IL","zip":"60647","homePhone":"773-446-5569","cellPhone":"773-352-3437","email":"viva.toelkes@gmail.com","website":"http://www.markivpressltd.com"}End Message Body ***************EventSource = aws:mqEventSourceARN = arn:aws:mq:us-west-2:123456789012:broker:ib-activemq-broker:b-aeb08c0d-6e46-412a-ad45-1507816242b0CorrelationID = TestMessage07-06-21-2023-06-06-02-78MessageID = ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:78MessageType = jms/text-messageReplyTo = nullType = TextMessageBrokerInTime = 1687328148538BrokerOutTime = 1687328148576DeliveryMode = 1Expiration = 0Priority = 4TimeStamp = 1687328148537Queue = LambdaActiveMQQueueWhetherRedelivered = falseThis person = {"firstname":"Viva","lastname":"Toelkes","company":"Mark Iv Press Ltd","street":"4284 Dorigo Ln","city":"Chicago","county":"Cook","state":"IL","zip":"60647","homePhone":"773-446-5569","cellPhone":"773-352-3437","email":"viva.toelkes@gmail.com","website":"http://www.markivpressltd.com"}Begin Message *************{"messageID":"ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:81","messageType":"jms/text-message","timestamp":1687328148540,"deliveryMode":1,"correlationID":"TestMessage07-06-21-2023-06-06-02-81","replyTo":"null","destination":{"physicalName":"LambdaActiveMQQueue"},"redelivered":false,"type":"TextMessage","expiration":0,"priority":4,"data":"eyJmaXJzdG5hbWUiOiJUaW1vdGh5IiwibGFzdG5hbWUiOiJNdWxxdWVlbiIsImNvbXBhbnkiOiJTYXJvbml4IE55bXBoIFByb2R1Y3RzIiwic3RyZWV0IjoiNDQgVyA0dGggU3QiLCJjaXR5IjoiU3RhdGVuIElzbGFuZCIsImNvdW50eSI6IlJpY2htb25kIiwic3RhdGUiOiJOWSIsInppcCI6IjEwMzA5IiwiaG9tZVBob25lIjoiNzE4LTMzMi02NTI3IiwiY2VsbFBob25lIjoiNzE4LTY1NC03MDYzIiwiZW1haWwiOiJ0aW1vdGh5X211bHF1ZWVuQG11bHF1ZWVuLm9yZyIsIndlYnNpdGUiOiJodHRwOi8vd3d3LnNhcm9uaXhueW1waHByb2R1Y3RzLmNvbSJ9","brokerInTime":1687328148541,"brokerOutTime":1687328148578}End Message ***************Begin Message Body *************{"firstname":"Timothy","lastname":"Mulqueen","company":"Saronix Nymph Products","street":"44 W 4th St","city":"Staten Island","county":"Richmond","state":"NY","zip":"10309","homePhone":"718-332-6527","cellPhone":"718-654-7063","email":"timothy_mulqueen@mulqueen.org","website":"http://www.saronixnymphproducts.com"}End Message Body ***************EventSource = aws:mqEventSourceARN = arn:aws:mq:us-west-2:123456789012:broker:ib-activemq-broker:b-aeb08c0d-6e46-412a-ad45-1507816242b0CorrelationID = TestMessage07-06-21-2023-06-06-02-81MessageID = ID:ip-10-192-10-195.us-west-2.compute.internal-33249-1687328148123-1:1:1:1:81MessageType = jms/text-messageReplyTo = nullType = TextMessageBrokerInTime = 1687328148541BrokerOutTime = 1687328148578DeliveryMode = 1Expiration = 0Priority = 4TimeStamp = 1687328148540Queue = LambdaActiveMQQueueWhetherRedelivered = falseThis person = {"firstname":"Timothy","lastname":"Mulqueen","company":"Saronix Nymph Products","street":"44 W 4th St","city":"Staten Island","county":"Richmond","state":"NY","zip":"10309","homePhone":"718-332-6527","cellPhone":"718-654-7063","email":"timothy_mulqueen@mulqueen.org","website":"http://www.saronixnymphproducts.com"}END RequestId: 30acfa0a-5be4-490b-9d02-f13814482aea
REPORT RequestId: 30acfa0a-5be4-490b-9d02-f13814482aea  Init Duration: 0.42 ms  Duration: 1218.03 ms    Billed Duration: 1219 ms        Memory Size: 512 MB    Max Memory Used: 512 MB

***** End sam local invoke response *****

Deploy the sample application

To deploy your application for the first time, run the following in your shell. Make sure the shell variable $AWS_REGION is set. If not, replace $AWS_REGION with the region in which you are deploying the AWS Lambda function:

sam deploy --capabilities CAPABILITY_IAM --no-confirm-changeset --no-disable-rollback --region $AWS_REGION --stack-name activemq-lambda-java-sam --guided

The sam deploy command will package and deploy your application to AWS, with a series of prompts. You can accept all the defaults by hitting Enter:

  • Stack Name: The name of the stack to deploy to CloudFormation. This should be unique to your account and region, and a good starting point would be something matching your project name.
  • AWS Region: The AWS region you want to deploy your app to.
  • Parameter ActiveMQBrokerArn: The ARN of the Amazon MQ (Apache ActiveMQ) broker that was created by the AWS CloudFormation template
  • Parameter ActiveMQQueue: The name of the Amazon MQ (Apache ActiveMQ) queue from which the lambda function will consume messages
  • Parameter SecretsManagerSecretForMQ: The ARN of the secret that has username/password for Amazon MQ (Apache ActiveMQ)
  • Parameter Subnet1: The first of the three private subnets where the Amazon MQ (Apache ActiveMQ) cluster is deployed
  • Parameter Subnet2: The second of the three private subnets where the Amazon MQ (Apache ActiveMQ) cluster is deployed
  • Parameter Subnet3: The third of the three private subnets where the Amazon MQ (Apache ActiveMQ) cluster is deployed
  • Parameter SecurityGroup: The security group of the lambda function. This can be the same as the security group of the EC2 instance that was created by the AWS CloudFormation template
  • Confirm changes before deploy: If set to yes, any change sets will be shown to you before execution for manual review. If set to no, the AWS SAM CLI will automatically deploy application changes.
  • Allow SAM CLI IAM role creation: Many AWS SAM templates, including this example, create AWS IAM roles required for the AWS Lambda function(s) included to access AWS services. By default, these are scoped down to minimum required permissions. To deploy an AWS CloudFormation stack which creates or modifies IAM roles, the CAPABILITY_IAM value for capabilities must be provided. If permission isn't provided through this prompt, to deploy this example you must explicitly pass --capabilities CAPABILITY_IAM to the sam deploy command.
  • Disable rollback: Defaults to No and it preserves the state of previously provisioned resources when an operation fails
  • Save arguments to configuration file: If set to yes, your choices will be saved to a configuration file inside the project, so that in the future you can just re-run sam deploy without parameters to deploy changes to your application.
  • SAM configuration file [samconfig.toml]: Name of the configuration file to store configuration information locally
  • SAM configuration environment [default]: Environment for storing deployment information locally

You should get a message "Successfully created/updated stack - in " if all goes well

Note: In case you want to deploy the Lambda function by pointing to an existing Amazon MQ (Apache ActiveMQ) Cluster and not the one created by running the AWS CloudFormation template provided in this pattern, you will need to modify the values of the above parameters accordingly

Test the application

Once the lambda function is deployed, send some messages to the Amazon MQ (Apache ActiveMQ) cluster on the queue that have been configured on the lambda function's event listener.

For your convenience, a Java program and a shell script has been created on the EC2 instance that was provisioned using AWS CloudFormation.

cd /home/ec2-user/serverless-patterns/activemq-private-lambda-java-sam/activemq_message_sender_json
chmod +x commands.sh

You should see a script called commands.sh. Run that script by passing a random string and a number between 1 and 500. Either send at least 10 messages or wait for 300 seconds (check the values of BatchSize: 10 and MaximumBatchingWindowInSeconds: 300 in the template.yaml file)

[ec2-user@ip-10-0-0-126 ~]$ sh ./commands.sh firstBatch 10

You should see output similar to what is shown below:

Sent out one message - Number 1 at time = 1760937987906 Sent out one message - Number 2 at time = 1760937987909 Sent out one message - Number 3 at time = 1760937987910 Sent out one message - Number 4 at time = 1760937987911 Sent out one message - Number 5 at time = 1760937987913 Sent out one message - Number 6 at time = 1760937987914 Sent out one message - Number 7 at time = 1760937987915 Sent out one message - Number 8 at time = 1760937987916 Sent out one message - Number 9 at time = 1760937987918 Sent out one message - Number 10 at time = 1760937987919

Once the messages have been sent, check Amazon CloudWatch logs and you should see messages for the Amazon CloudWatch Log Group with the name of the deployed Lambda function.

When you run the above script, it sends messages with JSON records to the Amazon MQ (Apache ActiveMQ) cluster on the queue on which the lambda function is listening on. The Lambda function listens on the published Amazon MQ (Apache ActiveMQ) messages on the queue.

The Lambda function code parses the Amazon MQ (Apache ActiveMQ) messages and outputs the fields in the messages to Amazon CloudWatch logs

The Lambda function also inputs each record into an Amazon DynamoDB table called ActiveMQDynamoDBTableJava (if you did not modify the default name in the sam template.yaml file)

You can go to the Amazon DynamoDB console and view the records.

You can also use the aws cli command below to view the count of records inserted into Amazon DynamoDB

aws dynamodb scan --table-name ActiveMQDynamoDBTableJava --select "COUNT"

Cleanup

You can first clean-up the Lambda function by running the sam delete command

cd /home/ec2-user/serverless-patterns/activemq-private-lambda-java-sam/activemq_consumer_dynamo_sam
sam delete

Confirm the delete by selecting Y at both prompts. AWS SAM confirms the stack deletion with the "Deleted successfully" message in the terminal.

Next you need to delete the AWS CloudFormation template that created the Amazon MQ (Apache ActiveMQ) cluster and the EC2 instance. Open the Amazon CloudFormation console, select the stack, then choose Delete. The delete will take some time.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.