/aws-sam-iterative-replacement-golang

A real-world starter template for migrating monoliths to serverless with AWS Serverless Application Model (AWS SAM) and the iterative replacement pattern.

Primary LanguageGoMIT LicenseMIT

AWS SAM iterative replacement template for Go

This repository contains an AWS SAM iterative replacement template. Iterative replacement allows you to migrate a monolith one route at a time by placing an Amazon API Gateway HTTP API in front of your existing application. Once all traffic is proxied through your HTTP API, you rewrite routes one at a time to serverless components. This enables you to modernize your monolith while reducing risk.

This template takes a single parameter, PassthroughTarget, of the form https://api.anycompany.com. Note that there is no trailing forward slash at the end of the target.

This template produces a single output, APIRoot, which is the root URL of your new HTTP API.

This template also includes two routes and an Amazon DynamoDB table to get you started:

  1. POST /customer to create a new record
  2. GET /customer/{id} to retrieve a record

These routes are integrated with two separate AWS Lambda functions, customer-read and customer-write. These functions execute with AWS SAM policy templates that appropriately restrict their access to the DynamoDB table.

How to use this template

  1. Install the AWS SAM CLI
  2. From a terminal, run sam init
  3. Select option 2 - Custom Template Location
  4. Enter gh:rts-rob/aws-sam-iterative-replacement-golang
  5. Provide a project name, e.g., hello-world
  6. Change into the created directory
  7. Build with sam build
  8. Deploy with sam deploy --guided
    • You will need to provide your existing application root URL as the value for the PassthroughTarget parameter, e.g., https://api.anycompany.com. Do not include a forward slash "/" at the end.

Now you have a sample application with Amazon API Gateway, Amazon DynamoDB, and AWS Lambda deployed and running in the region you specified. Your HTTP API will forward all traffic to your PassthroughTarget except for the routes you explicitly define in your AWS SAM template.

Next steps

Once deployed, implement your actual route logic one route and method at a time. Shift traffic to one completed route at a time, and monitor for any unexpected behavior.

Once you have iterated through all of your routes, congratulations! You've successfully migrated your monolith. You can shut down the underlying infrastructure, and refocus your ops efforts on improving performance for your customers.

Contributing

Issue reports and pull requests to help improve these application templates are always welcome. Please see CONTRIBUTING.md.

License

This project is licensed under the MIT License.