This pattern demonstrates how to build and deploy Fargate service using Go which receives messages from SQS queue and stores it in DynamoDB table.
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.
- 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.
- AWS CLI installed and configured with named AWS profile
- Git installed
- AWS CDK installed
- Go installed
- Docker installed
-
Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
git clone https://github.com/aws-samples/sqs-fargate-ddb-cdk-go.git
-
Change directory to the pattern directory:
cd sqs-fargate-ddb-cdk-go
-
From the command line, use the following commands to deploy the stack using CDK:
docker build -t go-fargate . cd cdk npm i cdk deploy --profile ${AWS_PROFILE}
In this pattern we created SQS queue, Fargate Service, and DynamoDB table. Fargate service is receiving messages from SQS queue using long polling (20 seconds) Once you send SQS message to the queue, Fargate service receives this message, processes it, and puts the message text into a new item of DynamoDB table.
- Open SQS console
- Find SQS queue with name
sqs-fargate-queue
- Press
Send and Receive message
button - Enter the message into "Message Body" field, e.g.
{
"message": "Hello, Fargate"
}
- Press
Send message
- Open ECS console
- Find cluster with name
go-service-cluster
- Find service named
go-fargate-service
- Open CloudWatch logs for an active task of this service and you'll see the messages from the service in the log.
- Open DynamoDB console and find
sqs-fargate-ddb-table
table - Press
Explore table items
button and you'll see messages that Fargate service put into the table.
- Check CloudWatch dashboard
go-service-dashboard
to monitor number of messages received from SQS and added into DynamoDB by the service.
- Delete the stack:
cd cdk cdk destroy --profile ${AWS_PROFILE}
- Confirm the stack has been deleted:
aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'SqsFargate')].StackStatus" --profile ${AWS_PROFILE}
This code is licensed under the MIT-0 License. See the LICENSE file.