AWS Builder Center
Amazon ECS for Beginners: How Containers Run on AWS, What Fargate Means and How to Keep Them Secure.

Amazon ECS for Beginners: How Containers Run on AWS, What Fargate Means and How to Keep Them Secure.

A guide to Amazon ECS: key terms, tasks and services, Fargate vs EC2, a simple task definition, limits, security habits and a checklist for students.

Final-year student learning AWS and cloud, aiming to earn Cloud Practitioner and be a data engineer.

1. Understanding the terms

What is a container? A container packages an application together with everything it needs to run (code, libraries and settings), so it behaves the same on any machine.
What is a container image? An image is the template a container is created from. You build it from a Dockerfile.
What is Amazon ECR? Amazon Elastic Container Registry (ECR) is AWS’s registry for storing images, similar to GitHub for code.
What is Amazon ECS? Amazon Elastic Container Service (ECS) is a fully managed container orchestration service. You tell it which containers to run, and it starts them, keeps them running and replaces any that fail.
What is a cluster? A cluster is a logical group of tasks or services.
What is a task definition? A task definition is a blueprint, written in JSON. It says which image to use, how much CPU and memory to give, which ports to open, which roles to use and where to send logs.
What is a task? A task is a running copy of a task definition. It is one or more containers running together.
What is a service? A service keeps a set number of tasks running. If a task stops, the service starts a new one. It can also work with a load balancer and scale tasks up or down.
What is Fargate? Fargate is the serverless way to run ECS tasks. You choose the CPU and memory, and AWS provides the compute, so you don’t manage servers.

2. How ECS works

  1. I build a container image and push it to ECR.
  1. I write a task definition that points to the image.
  1. I create a cluster and a service that uses the task definition.
  1. The service launches tasks on the chosen capacity (Fargate or EC2).
  1. Logs go to CloudWatch, and the service replaces any task that fails.
ECS is the manager, and Fargate or EC2 is where the containers actually run.

3. Where containers can run

Option
What it means
Best for
Fargate
AWS manages the infrastructure, and I only set CPU and memory per task
Beginners and teams that want no servers to manage
EC2
I choose and manage the instances, including patching and scaling them
Workloads needing full control or specific instance types
ECS Managed Instances
A newer option that mixes EC2 flexibility with AWS-managed operations
Teams who want EC2 features without managing instances
External (ECS Anywhere)
Runs tasks on my own on-premises machines
Hybrid setups
For learning, Fargate is the easiest place to start.

4. A simple example

This is a minimal task definition for a small web container on Fargate:
json
{
"family": "hello-web",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "256",
"memory": "512",
"executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole",
"containerDefinitions": [
{
"name": "web",
"image": "123456789012.dkr.ecr.ap-south-1.amazonaws.com/hello-web:1.0.0",
"portMappings": [{ "containerPort": 80 }],
"essential": true
}
]
}
The account ID ( 123456789012 ) and image name are placeholders. Replace them with your own and never share real account details publicly. Notice the image has a version tag ( 1.0.0 ) instead of  latest , which makes deployments predictable.

5. Limits to know

ECS has many service quotas, and most can be raised through the Service Quotas console. A few things I learned:
  • Services that use ECS service discovery are limited to 1,000 tasks per service.
  • Fargate also enforces limits on how fast tasks can be launched, and the vCPU limit per Region can stop a launch.
  • Quotas vary by Region and account, so check the Service Quotas console before a launch or traffic spike.

6. How pricing works

ECS itself has no extra charge. I pay for the compute that runs the containers, which is Fargate vCPU and memory per second, or the EC2 instances I use. I also pay for related services such as load balancers, data transfer and CloudWatch logs. Check the AWS pricing pages for current numbers.

7. Security: what a developer should do

ECS is managed by AWS, but how I configure it is my responsibility.
Use two separate roles, each with least privilege.
  • The task execution role lets ECS pull the image and write logs.
  • The task role is what my application uses to reach AWS services, such as reading one S3 bucket.
Never put secrets in the image or the task definition text. Use AWS Secrets Manager or Systems Manager Parameter Store.
Scan and pin images. Turn on image scanning in ECR, use version tags or digests instead of  latest , and use trusted base images. Recent security news has shown how a compromised package or image can reach many systems.
Protect the network. Run tasks in private subnets where possible, use tight security groups, and expose only what is needed through a load balancer.
Turn on logging and alarms. Send container logs to CloudWatch and set alarms for failed tasks and high CPU or memory.
Keep base images updated. Rebuild and redeploy regularly so security fixes reach running containers.

8. Common beginner mistakes

  • Using one very broad role for everything
  • Putting passwords or keys inside the image
  • Using the  latest  tag, then not knowing which version is running
  • Giving tasks public IP addresses and open security groups for no reason
  • Forgetting to set CPU and memory limits
  • Having no logs, so a failed task can’t be debugged
  • Leaving test services running and paying for them

9. ECS, Lambda, EKS and EC2: when to use which

Need
Good fit
Short event-driven task under 15 minutes
Lambda
Long-running app or API in containers, AWS-native
ECS (usually on Fargate)
Existing Kubernetes skills or multi-cloud needs
EKS
Full control of the server, or an older app
EC2
I’m treating ECS on Fargate as the simplest way to run containers on AWS without learning Kubernetes first.

10. A practical checklist

For students and beginners
  • Create a free AWS account and set a budget alert first.
  • Build a small Docker image locally and run it.
  • Push it to ECR, run it as a Fargate task and read the logs in CloudWatch.
  • Delete the service and cluster when you finish.
For developers
  • Keep images small and tag them with versions.
  • Keep secrets out of images and task definitions.
  • Add a health check to your container.
For cloud engineers
  • Give every service its own task role with least privilege.
  • Turn on ECR image scanning.
  • Use private subnets and tight security groups.
  • Set alarms and check quotas before launches.
  • Clean up unused clusters, services and images.



Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article