Deploying to AWS is hard. Here are some tips.
There are loads of ways to deploy an application to AWS. If you want to avoid lock-in, though, you probably want to containerize your application. You can read more about the benefits of containers here. We also find it particularly useful to use Compose files to define how your application should run alongside other services like databases, caches, object storage, etc.
Okay. So now that we've containerized our application. How do we run it on AWS? AWS offers many ways to run containers, but we'll focus on three of the most common ways: a single EC2 instance, ECS, and EKS.
Prerequisites: You'll need an AWS account and the AWS CLI
In each of these cases, it's probably a good idea to have the AWS CLI installed. You can find instructions on how to do that here and here.
Single EC2 Instance. Simple, but not production ready.
The simplest way to run a container on AWS is to create an EC2 instance (a Virtual Machine) and run your container on it. This is fine for development and testing, but not great for production-ready apps: if your instance goes down, your application goes down, and you cannot scale your application easily if your traffic increases.
To deploy a container with EC2 you'll need to use an AMI like this one from Docker. You'll also need to do things like pull your code manually and rebuild/run when you have any updates. Or you can run builds in a CD pipeline, push those to a registry like ECR, and then pull those images onto your instance and restart your Compose project.
Why deploy to AWS with Defang?
Scalability
Defang helps you provision your AWS resources like VPCs, ECS clusters, DNS records, certificates, and more so that you can easily scale your application as your traffic grows.
Security
It's easy to make mistakes that leave your application vulnerable. Defang provisions security groups and IAM roles, and helps you manage sensitive configuration values.
Observability
Defang sets up logging and monitoring for your application so you can easily see what's going on and debug any issues that arise with a simple command line tool.
ECS. Great for most apps.
Amazon ECS is a managed container orchestration service from AWS. It's great for most applications. You can run your containers across multiple instances, and ECS will allow you to do things like horizontal scaling, rolling updates, and more to keep your application running smoothly as you grow.
To get started with ECS, you'll need to create a cluster and a task definition that describes how your containers should run. You'll also need to create a service that tells ECS how many copies of your task to run and how to load balance traffic across them.
Similarly to the EC2 instance, you'll also need to build your images somehow, probably using a CD pipeline, push those to a registry like ECR, and then update your service to use the new image.
EKS. When you have a DevOps team.
Amazon EKS is a managed Kubernetes service from AWS. It's great if you have a DevOps team that is already familiar with Kubernetes and if you have more complex requirements. It also allows you to take advantage of the extensive library of Helm charts that are available. Kubernetes is very powerful, but it's also very complex, and it can be difficult to manage. EKS is a lot more expensive than ECS too, so you should only use it if you need the extra capabilities.
To get started with EKS, you'll need to create a cluster and a deployment that describes how your containers should run. You'll also need to create a service that tells Kubernetes how to load balance traffic across your containers.
Similarly to ECS, you'll also need to build your images somehow, probably using a CD pipeline, push those to a registry like ECR, and then update your deployment to use the new image.
Defang. The easy way to deploy to AWS.
Defang makes it easy to deploy your containerized application to your own AWS account. All you have to do is run defang --provider=aws compose up
and we'll do all the heavy lifting for you.
Defang exists to make it easy to deploy to AWS and other clouds, so you can benefit from all the power they provide. We realized that there are a lot of things that you need to set up to run an application properly in the cloud, and that it's easy to make mistakes that leave your application vulnerable and make it hard to scale. Defang takes care of all of that for you, so you can get all the benefits of running in AWS without any of the headaches.
You can read more about how Defang works and how to get started here. Basically, though, we take care of all the hard parts of deploying to AWS using ECS for you.