---
title: "Container Service on AWS"
description: "Deploy a container service on AWS with Pulumi, Amazon ECS on Fargate, and Amazon ECR in TypeScript, Python, Go, C#, YAML, or HCL."
url: "https://www.pulumi.com/dev/templates/container-service/aws/"
image: "https://www.pulumi.com/assets/og/dev/templates/container-service/aws.png"
---

# Container Service on AWS

Deploy a container service on AWS with Pulumi, Amazon ECS on Fargate, and Amazon ECR in TypeScript, Python, Go, C#, YAML, or HCL.

The AWS Container Service template scaffolds a Pulumi project that deploys a containerized service to AWS. The architecture includes an [Amazon ECS cluster](https://www.pulumi.com/registry/packages/aws/api-docs/ecs/cluster) for orchestration, [AWS Fargate](https://www.pulumi.com/registry/packages/awsx/api-docs/ecs/fargateservice/) for serverless compute, an [Application Load Balancer](https://www.pulumi.com/registry/packages/awsx/api-docs/lb/) for internet ingress, and an [Amazon Elastic Container Registry (ECR)](https://www.pulumi.com/registry/packages/awsx/api-docs/ecr/repository) repository for the container image. The template ships with an Nginx Dockerfile so the project deploys end to end out of the box.

![An architecture diagram of the AWS Container Service template](./architecture.png)

## Using this template

To use this template to deploy an ECS cluster running your container service, make sure you've [installed Pulumi](https://www.pulumi.com/docs/install/) and [configured your AWS credentials](https://www.pulumi.com/registry/packages/aws/installation-configuration#credentials), then create a new [project](https://www.pulumi.com/docs/iac/concepts/projects/) using the template in the language of your choice:

**TypeScript**

```bash
mkdir my-container-service && cd my-container-service
pulumi new container-aws-typescript
```

**Python**

```bash
mkdir my-container-service && cd my-container-service
pulumi new container-aws-python
```

**Go**

```bash
mkdir my-container-service && cd my-container-service
pulumi new container-aws-go
```

**C#**

```bash
mkdir my-container-service && cd my-container-service
pulumi new container-aws-csharp
```

**YAML**

```bash
mkdir my-container-service && cd my-container-service
pulumi new container-aws-yaml
```

**HCL**

```bash
mkdir my-container-service && cd my-container-service
pulumi new container-aws-hcl
```

Follow the prompts to complete the new-project wizard. When it's done, you'll have a complete Pulumi project that's ready to deploy and configured with the most common settings. Feel free to inspect the code in `index.ts` for a closer look.

## Deploying the project

The template requires no additional configuration. Once the new project is created, you can deploy it immediately with [`pulumi up`](https://www.pulumi.com/docs/iac/cli/commands/pulumi_up):

```bash
$ pulumi up
```

When the deployment completes, Pulumi exports the following [stack output](https://www.pulumi.com/docs/iac/concepts/stacks/#outputs) values:

**`url`**

The HTTP URL for the container's endpoint.

Output values like these are useful in many ways, most commonly as inputs for other stacks or related cloud resources. The computed `url`, for example, can be used from the command line to open the newly deployed container service in your favorite web browser:

```bash
$ open $(pulumi stack output url)
```

## Customizing the project

Projects created with the Container Service template expose the following [configuration](https://www.pulumi.com/docs/iac/concepts/config/) settings:

**TypeScript / Python / Go / C# / YAML**

**`container_port`**

Specifies the port mapping for the container. Defaults to port 80.

**`cpu`**

Specifies the amount of CPU to use with each task or each container within a task. Defaults to 512.

**`memory`**

Specifies the amount of memory to use with each task or each container within a task. Defaults to 128.

**`image`**

Specifies the location of the Dockerfile used to build the container image that is run. Defaults to the Dockerfile in the `app` folder.

**HCL**

**`container_port`**

Specifies the port mapping for the container. Defaults to port 80.

**`cpu`**

Specifies the amount of CPU to use with each task or each container within a task. Defaults to 512.

**`memory`**

Specifies the amount of memory to use with each task or each container within a task. Defaults to 128.

All of these settings are optional and may be adjusted either by editing the stack configuration file directly (by default, `Pulumi.dev.yaml`) or by changing their values with [`pulumi config set`](https://www.pulumi.com/docs/iac/cli/commands/pulumi_config_set):

### Using your own container image

**TypeScript / Python / Go / C# / YAML**

If you already have a container image you'd like to build your container service with, you can do so either by replacing the Dockerfile in the `app` folder or by configuring the stack to point to another folder on your computer with the `image` setting:

```bash
$ pulumi config set image ../my-existing-image
$ pulumi up
```

**HCL**

If you already have a container image you'd like to build your container service with, you can do so by replacing the Dockerfile and application code in the `app` folder, then redeploying with `pulumi up`.

## Cleaning up

You can cleanly destroy the stack and all of its infrastructure with [`pulumi destroy`](https://www.pulumi.com/docs/iac/cli/commands/pulumi_destroy):

```bash
$ pulumi destroy
```

## Learn more

- Browse other architecture templates in the [Templates gallery](https://www.pulumi.com/templates).
- Explore the [AWS](https://www.pulumi.com/registry/packages/aws/) and [AWSx](https://www.pulumi.com/registry/packages/awsx) provider API docs in the Pulumi Registry.
- Walk through Pulumi from the ground up in [Pulumi Tutorials](https://www.pulumi.com/dev/browse/?type=tutorial).
- Read the latest [container posts on the Pulumi blog](https://www.pulumi.com/blog/tag/containers).
