0
0
AWScloud~5 mins

Why container services matter on AWS - Why It Works

Choose your learning style9 modes available
Introduction
Running applications can be tricky when you have many parts that need to work together. Container services on AWS help by packaging these parts so they run smoothly and reliably without conflicts.
When you want to run multiple apps on the same server without them interfering with each other
When you need to quickly start or stop parts of your app without affecting the whole system
When you want to easily move your app from your computer to the cloud without changing it
When you want AWS to handle the work of managing servers for your app
When you want your app to automatically handle more users by adding more containers
Commands
This command creates a new container cluster on AWS ECS where your containers will run.
Terminal
aws ecs create-cluster --cluster-name my-app-cluster
Expected OutputExpected
{ "cluster": { "clusterArn": "arn:aws:ecs:us-east-1:123456789012:cluster/my-app-cluster", "clusterName": "my-app-cluster", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "runningTasksCount": 0, "pendingTasksCount": 0, "activeServicesCount": 0 } }
--cluster-name - Names the ECS cluster you want to create
This command registers a task definition that tells ECS how to run your container, including which image to use and resource limits.
Terminal
aws ecs register-task-definition --cli-input-json file://task-definition.json
Expected OutputExpected
{ "taskDefinition": { "taskDefinitionArn": "arn:aws:ecs:us-east-1:123456789012:task-definition/my-app-task:1", "containerDefinitions": [ { "name": "my-app-container", "image": "nginx:latest", "cpu": 256, "memory": 512, "essential": true } ], "family": "my-app-task", "revision": 1 } }
--cli-input-json - Provides the task definition details from a JSON file
This command creates a service that runs and maintains the desired number of container tasks in your cluster.
Terminal
aws ecs create-service --cluster my-app-cluster --service-name my-app-service --task-definition my-app-task --desired-count 1
Expected OutputExpected
{ "service": { "serviceName": "my-app-service", "clusterArn": "arn:aws:ecs:us-east-1:123456789012:cluster/my-app-cluster", "status": "ACTIVE", "desiredCount": 1, "runningCount": 1 } }
--cluster - Specifies the cluster where the service will run
--service-name - Names the service you are creating
--desired-count - Sets how many container tasks should run
This command lists the running tasks in your cluster so you can check if your containers are running.
Terminal
aws ecs list-tasks --cluster my-app-cluster
Expected OutputExpected
{ "taskArns": [ "arn:aws:ecs:us-east-1:123456789012:task/my-app-cluster/abcdef1234567890" ] }
--cluster - Specifies the cluster to list tasks from
Key Concept

If you remember nothing else from this pattern, remember: container services on AWS let you run and manage app parts easily and reliably without worrying about servers.

Common Mistakes
Not creating a cluster before registering tasks or services
Tasks and services need a cluster to run in; without it, commands fail.
Always create an ECS cluster first using aws ecs create-cluster.
Using incorrect or missing task definition JSON when registering tasks
ECS needs a valid task definition to know how to run containers; invalid JSON causes errors.
Prepare a correct task-definition.json file with container details before registering.
Setting desired count to zero when creating a service
This means no containers will run, so your app won't be available.
Set desired count to at least 1 to run your container tasks.
Summary
Create an ECS cluster to provide a place for containers to run.
Register a task definition that describes your container setup.
Create a service to run and maintain your containers in the cluster.
Check running tasks to verify your containers are active.