Skip to content

aws-samples/sqs-fargate-ddb-cdk-go

Build and deploy message processing service using Fargate

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.

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.
  • AWS CLI installed and configured with named AWS profile
  • Git installed
  • AWS CDK installed
  • Go installed
  • Docker installed

Deployment Instructions

  1. 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
    
  2. Change directory to the pattern directory:

    cd sqs-fargate-ddb-cdk-go
    
  3. 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}
    

How it works

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.

Testing

  1. Open SQS console
  2. Find SQS queue with name sqs-fargate-queue
  3. Press Send and Receive message button
  4. Enter the message into "Message Body" field, e.g.
{
    "message": "Hello, Fargate"
}

image1

  1. Press Send message
  2. Open ECS console
  3. Find cluster with name go-service-cluster
  4. Find service named go-fargate-service
  5. Open CloudWatch logs for an active task of this service and you'll see the messages from the service in the log.

image2

  1. Open DynamoDB console and find sqs-fargate-ddb-table table
  2. Press Explore table items button and you'll see messages that Fargate service put into the table.

image3

  1. Check CloudWatch dashboard go-service-dashboard to monitor number of messages received from SQS and added into DynamoDB by the service.

Cleanup

  1. Delete the stack:
    cd cdk
    cdk destroy --profile ${AWS_PROFILE}
    
  2. Confirm the stack has been deleted:
    aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'SqsFargate')].StackStatus" --profile ${AWS_PROFILE}
    

License

This code is licensed under the MIT-0 License. See the LICENSE file.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •