Quickly spin up a microservices stack on AWS What is a microservice? The architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies. Credit microservice [1] Martin Fowler If you are new to microservices please read Martin Fowler’s in its entirety. article What is a stack? A is a collection of AWS resources that you can manage as a single unit. In other words, you can create, update, or delete a collection of resources by creating, updating, or deleting . All the resources in a are defined by the AWS template. stack stacks stack stack’s CloudFormation What is the ? Services Stack The is one example of how you can architect, develop, and deploy microservices on AWS. Specifically using AWS , , and . services stack Virtual Private Cloud (VPC) EC2 Container Registry (ECR) EC2 Container Service (ECS) Here is what the architecture looks like. services stack If you are ready to deploy this stack and start building microservices then click . here The Services Stack Lets learn more about the components that make up this stack. Virtual Private Cloud (VPC) The first building block is the . Think of the VPC as a security and isolation layer that everything else we deploy lives inside. Within the VPC we have public subnets and private subnets. AWS VPC For the most part we put everything important (apps, databases, etc…) in the private subnets. Then we put all communication resources (ALB’s, Gateway’s) in the public subnets. Communication resources being things that bridge the gap between our hidden services and the internet. For example our goes in the private subnets but our goes in the public subnets. When inbound requests are made to our service they go through the ALB. The internet can talk to our ALB but can’t talk directly to our service. Only the ALB can talk to our service. service Application Load Balancer (ALB) Outbound requests from or to the internet go through the which are also in the public subnets. service NAT Gateway’s, EC2 Container Registry (ECR) is a fully-managed container registry that makes it easy for developers to store, manage, and deploy Docker container images. AWS ECR Docker Think of the container registry as a repository of your build artifact, with versioning, which are ready to run. You simply tell ECS to deploy this version of this artifact. We need an ECR repo for each of our services. What is a container? are a method of operating system virtualization that allow you to run an application and its dependencies in resource-isolated processes. allow you to easily package an application’s code, configurations, and dependencies into easy to use building blocks that deliver environmental consistency, operational efficiency, developer productivity, and version control. Read more about . Containers Containers containers here What is Docker? is the software that helps you develop, package, and deploy your containers. Read more about containers . Docker Docker here EC2 Container Service (ECS) is a highly scalable, high performance management service that supports containers and allows you to easily run applications on a managed cluster of Amazon EC2 instances. AWS ECS container Docker One or more EC2 instances can run many Docker container services. So you could have one EC2 instance running many services. Container services make it easier for you to develop, deploy, and scale Docker containers across a set of EC2 instances. Application Load Balancer (ALB) operates at the request level (layer 7), routing traffic to targets (containers) based on the content of the request. AWS ALB In our case the ALB sits inside the public subnets and routes HTTP traffic to our service based on the URI. The ALB is also smart enough to know which port in each EC2 instance our service is running on so it can route traffic accordingly. A common setup is an ALB with the following routing rules: https://yourdomain.com/service1 -> service 1 https://yourdomain.com/service2 -> service 2 Microservice — Service 1 Finally the code. Our service is a simple web application that responds to HTTP requests. It can be in any language or framework. The beauty of this architecture is that the implementation details are not needed by the compute layer. They are encapsulated in the container definition, the Dockerfile. To deploy this stack we use CIM. What is CIM? Before building anything on AWS I always start with CloudFormation. IaC is a must for all projects built on AWS. Plus it’s really fun and makes you feel like a true architecture. CloudFormation had a few pain points. That’s why I built . CIM is a simple command line utility that bootstraps your CRUD operations, making them easier to execute, repeatable, and less error-prone. CIM CloudFormation If you want to learn more about , and why I built it, you can read my article, . CIM Meet CIM — Cloud Infrastructure Manager Thanks for reading about the Services Stack. I hope you enjoyed it.