Skip to main content
This guide shows how to deploy an Amazon ECS service using the Fargate launch type and distribute tasks across multiple Availability Zones (Multi‑AZ). It covers the full workflow: Recommended reading:

1. Create an ECS cluster (Fargate)

Open the Amazon Elastic Container Service console, go to the left panel and select Clusters, then choose Create cluster. Choose the Fargate option so AWS manages the underlying compute and you only manage the tasks and task definitions. Give the cluster a clear name, for example demo-cluster.
A screenshot of the AWS Elastic Container Service "Create cluster" page showing compute capacity options. The "Fargate only" option is selected among choices for Fargate, managed, or self‑managed instances.
Fargate is a serverless compute engine for containers: the servers exist but AWS handles provisioning, patching, and scaling so you don’t manage EC2 instances directly. If this is the first ECS cluster in the account, you might see this error: “Error creating cluster demo-cluster. Reason: unable to assume the service-linked role. Please verify that the ECS service-linked role exists.” This is a known first-time setup issue in some AWS accounts. Retry creating the cluster — AWS will create the required ECS service-linked role automatically on the next attempt.
If you see an “unable to assume the service-linked role” error on first cluster creation, retry creating the cluster. AWS will then create the required ECS service-linked role and the issue will not recur.

2. Create a Fargate task definition

From the left panel choose Task Definitions → Create new task definition. Enter a name such as DemoTaskDefinition and select the AWS Fargate launch type under Infrastructure requirements.
A screenshot of the Amazon Elastic Container Service "Create new task definition" page showing the Infrastructure requirements section with the AWS Fargate launch type checked. The page also lists other launch options like Managed Instances and Amazon EC2.
For this demo, keep the defaults (1 vCPU and 3 GiB memory are fine). Leave the task role and task execution role at defaults. The task execution role (for example, ecsTaskExecutionRole) allows ECS to pull images and publish logs; the task role is used if your application needs to call AWS APIs.
A screenshot of the Amazon Elastic Container Service "Create new task definition" page. It shows task role and task execution role settings (with ecsTaskExecutionRole selected) and "Create new role" buttons.
Add a container to the task definition:
  • Name: demo-container
  • Image: use the public Apache HTTP Server image for this demo
  • Container port: 80 (protocol TCP, app protocol HTTP)
  • Leave “Essential” enabled and other advanced options at defaults for the demo.
A screenshot of the Amazon Elastic Container Service "Create new task definition" page in the AWS console showing options for private registry authentication and port mappings. The port mapping fields display container port 80, protocol TCP and app protocol HTTP with buttons to add or remove mappings.
Create the task definition. After creation you’ll see the task definition details and its revision number.
A screenshot of the AWS Elastic Container Service console displaying the task definition "DemoTaskDefinition:9." It shows details like the ARN, status (ACTIVE), creation time, app environment (Fargate), and buttons for Deploy/Create new revision.

3. Create a service (keep tasks running across AZs)

In the Cluster view select Create → Create Service. Choose the task definition family you created and an optional revision. Name the service, for example DemoService.
A screenshot of the Amazon Elastic Container Service "Create service" page showing the task definition family set to "DemoTaskDefinition" with fields for task definition revision and service name. The AWS console header and browser tab are visible at the top.
Select Fargate as the launch type and set the platform version to LATEST if prompted.
A screenshot of the AWS Management Console on the Amazon Elastic Container Service "Create service" page, showing the Launch type option with "Fargate" selected and platform version set to "LATEST." The browser header and account name "CloudWithDjango-Org" are visible at the top.
  • Set Desired tasks to 2 so ECS will maintain two running copies.
  • Networking: select your default VPC and choose subnets that span different Availability Zones. For two desired tasks, select two subnets in two different AZs (for example us-east-2a and us-east-2b). For three tasks choose three AZ subnets.
A screenshot of the AWS Management Console on the Amazon Elastic Container Service "Create service" page showing VPC and subnet selection fields with three subnets listed (us-east-2a/2b/2c). The browser header and AWS navigation controls are visible at the top.
Security group: ensure ingress allows HTTP (port 80) from the expected sources. For a public demo you might allow ingress from 0.0.0.0/0, but do so only for non-production testing.
Allowing HTTP (port 80) from 0.0.0.0/0 exposes the service to the public internet. For production use, restrict access with specific IP ranges, a load balancer with proper security controls, or other network controls.
Important networking notes:
  • Selecting subnets across multiple AZs improves resilience and placement, but does not automatically make tasks reachable from the internet.
  • To expose tasks publicly: enable auto-assign public IP when placing tasks into public subnets, or (recommended) put the service behind a public-facing load balancer and configure listeners/target groups.
After verification, create the service. ECS will launch tasks and attempt to place them across the selected subnets/AZs.

4. Cleanup

When finished, remove resources to avoid ongoing charges:
  • Stop or delete the service from within the cluster—the service will drain and stop tasks.
  • Delete the cluster from the Clusters page (you will be asked to type the cluster name to confirm).
A browser screenshot of the AWS Elastic Container Service console showing a modal asking to permanently delete a cluster named "DemoCluster." The dialog requires typing the phrase "delete DemoCluster" to confirm and shows Cancel and Delete buttons.
  • Deregister task definition revisions you no longer need from the Task Definitions page; deregistered revisions won’t be available for new deployments. Refresh the Task Definitions view to confirm removal.
A screenshot of the AWS Elastic Container Service console showing a task definition named "DemoTaskDefinition" with the Actions menu open (option to "Deregister") and buttons for "Deploy" and "Create new revision." The task revision DemoTaskDefinition:9 is shown as Active.

Quick reference


That concludes the step-by-step Fargate multi‑AZ ECS deployment. You now have a service running two tasks across two Availability Zones and the knowledge to safely tear down the environment.

Watch Video