The Amazon Web Services (AWS) Cloud ecosystem is large and vibrant, so vast and vibrant that at times, it can be challenging to know where best to start! In the case of [containers](https://www.pulumi.com/containers/), [Abby Fuller](https://twitter.com/abbyfuller) tweeted a descriptive summary about using AWS container services.
It looks straightforward, but it's easy to get lost in the details when configuring multiple services to get your application running on AWS. Although AWS has extensive documentation and a point and click interface to these services, replicating then can be challenging, and it isn't conducive to understanding the architecture. However, using infrastructure as code lets you see the details and results in a reproducible deployment that you can expand on. Let’s implement the diagram using Pulumi to deploy your container infrastructure with code in AWS.
The AWS Elastic Container Registry (ECR) is a container registry that supports private container registries. ECR makes it easy to store, build, manage, and deploy container images and eliminates the need to operate your registry or use public registries, all in a highly available and scalable architecture.
In this example, we use Pulumi’s [Crosswalk for AWS](/docs/clouds/aws/guides/). Crosswalk for AWS is a collection of frequent tasks and best practices that simplify deploying infrastructure on AWS. We first declare a repository; this creates the AWS Container Repository resource. The last line of the code exports the URL so that we can access the repository after we have updated our Pulumi stack. After we’ve run `pulumi up`, the repository is ready to go, and you can use the Docker CLI to push, pull, and manage images.
There are two services for running containers in the AWS Cloud: Elastic Cloud Service (ECS), or Elastic Kubernetes Service (EKS). ECS is a proprietary service for running containers in the AWS Cloud. In contrast, EKS is a managed Kubernetes service for containers using a Kubernetes control plane. It has three master nodes distributed across three availability zones to provide high availability.
ECS is designed to work with other AWS services and provides more straightforward configuration and integration with them while providing high availability. In contrast, EKS is a managed Kubernetes service, and because Kubernetes is open-source, your infrastructure is portable to other cloud providers. Also, Kubernetes can provide fine-grain control over deployed services. The choice of which scheduler to use depends on your requirements.
You can create either an ECS or EKS cluster using Pulumi. If you wish to use ECS, @pulumi/aws provides all the primitives needed to build infrastructure on AWS.
// Create an EKS cluster with the default configuration.
const cluster = new eks.Cluster("my-cluster");
```
## Choose where/how to run, Fargate or EC2
Fargate is an AWS service that runs containers. It is suited to running small workloads or batch workloads with occasional bursts that require scaling quickly. AWS EC2 is ideal for large workloads requiring many CPU cores and gigabytes of memory.
With Kubernetes, we create a deployment for the application and a service to make the application accessible via port 80. We publish both application endpoint to make it accessible and cluster config for use with `kubectl` CLI.
Let’s put it all together for both ECS and EKS. To get started, follow the [Pulumi AWS documentation](/docs/clouds/aws/get-started/) to install Pulumi, [install AWS Client](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv1.html) set your [AWS environment variables](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and [create a new project](/docs/clouds/aws/get-started/) in Typescript.
In this example, we build the application in code using the `awsx.ecr.Image` resource. This resource uses Docker to build the image locally and push it to our repository. Make sure that you have [Docker installed and running](https://docs.docker.com/install/#supported-platforms).
Now we're ready to start building our infrastructure. Replace the generated `index.ts` file with the example below. The example shows how to deploy containers on ECS using Fargate.
To deploy the application, run `pulumi up`. You'll see a preview of the resources to be deployed. Accept the deployment by selecting `yes`, and when finished, your program lists the URLs for the application and the repository.
The EKS example uses the `@pulumi/eks` and `@pulumi/kubernetes` node modules. Add the [eks](https://www.npmjs.com/package/@pulumi/eks) and [kubernetes](https://www.npmjs.com/package/@pulumi/kubernetes) modules to the project.
Like the ECS example, the EKS example builds the application image locally and pushes it into our custom repository. The application deployment has two replicas in the configuration. The service uses the EKS cluster, `my-cluster`, we declared to create a load balancer with port 80 open.
Although these examples are simple, they demonstrate the basic building blocks for building, storing, and managing AWS Containers. They also show how to create ECS or EKS clusters for deploying apps. To get started with AWS and Pulumi check out the [AWS Guide](/docs/clouds/aws/get-started/) for core services and the [Crosswalk for AWS guide](/docs/clouds/aws/guides/) for convenience APIs that simplify deploying infrastructure as code. For a deeper dive into managing containers on AWS, check out our blogs on [ECS vs Fargate vs EKS: The Lowdown on Containers in AWS](https://www.pulumi.com/blog/running-containers-in-aws-the-lowdown-ecs-fargate-and-eks/) and [How to Scale Your Amazon EKS Cluster: EC2, Managed Node Groups, and Fargate](/blog/aws-eks-managed-nodes-fargate).