This repository (based on the reference architecture located here) provides a set of YAML templates for deploying microservices to Amazon EC2 Container Service (Amazon ECS) with AWS CloudFormation.
If you're in a hurry:
- First, deploy an VPC for your environment (prod, dev, staging, etc) using this template . Fill the Environment Name field with the same value as the Stack Name field.
- Then, deploy an ECS cluster that uses the VPC that you've created. Type the VPC Environment Name into the Existing VPC to attach field (another VPC will be created if this field is empty). If you want to use On Demand instances, use this template . If you want to use Spot Instances, use this template .
- You can have more than one ECS cluster within each VPC that you create - one on-demand cluster for web-based containers and another spot cluster for batch processes is nice!
- That's it! :D
The repository consists of a set of nested templates that deploy the following:
- A tiered VPC with public and private subnets, spanning an AWS region.
- A highly available ECS cluster deployed across two Availability Zones in an Auto Scaling group.
- A pair of NAT gateways (one in each zone) to handle outbound traffic.
- Two interconnecting microservices deployed as ECS services (website-service and product-service).
- An Application Load Balancer (ALB) to the public subnets to handle inbound traffic.
- ALB path-based routes for each ECS service to route the inbound traffic to the correct service.
- Centralized container logging with Amazon CloudWatch Logs.
The templates below are included in this repository and reference architecture:
Template | Description |
---|---|
master-normal.yaml | This is the master template for an ECS cluster with On Demand instances - deploy it to CloudFormation and it includes all of the others automatically. |
master-spot.yaml | This is the master template for an ECS cluster with Spot instances - deploy it to CloudFormation and it includes all of the others automatically. |
infrastructure/vpc.yaml | This template deploys a VPC with a pair of public and private subnets spread across two Availability Zones. It deploys an Internet gateway, with a default route on the public subnets. It deploys a pair of NAT gateways (one in each zone), and default routes for them in the private subnets. |
infrastructure/security-groups.yaml | This template contains the security groups required by the entire stack. They are created in a separate nested template, so that they can be referenced by all of the other nested templates. |
infrastructure/load-balancers.yaml | This template deploys an ALB to the public subnets, which exposes the various ECS services. It is created in in a separate nested template, so that it can be referenced by all of the other nested templates and so that the various ECS services can register with it. |
infrastructure/ecs-cluster.yaml | This template deploys an ECS cluster to the private subnets using an Auto Scaling group. |
services/dd-agent/service.yaml | This is an long-running ECS service that monitors your cluster and apps with Datadog. |
After the CloudFormation templates have been deployed, the stack outputs contain a link to the load-balanced URLs for each of the deployed microservices.
Copyright 2017 TruckPad. All Rights Reserved.
Copyright 2011-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
http://aws.amazon.com/apache2.0/
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.