Skip to main content

Command Palette

Search for a command to run...

Difference between task role and execution role in AWS ECS

Updated
2 min read
Difference between task role and execution role in AWS ECS

Today, I want to explain the difference between a task role and an execution role in AWS ECS. Yesterday, I set up AWS ECS for a UAT environment and defined both roles. Let me clarify what a task role and an execution role are, when they are needed, and who uses them.

ECS Task Execution role

In my setup, my container needs to access ECR for pulling Docker images and needs to send logs to CloudWatch. My container needs to retrieve the DB password from AWS Secrets Manager. If I didn't define this execution role, my container couldn't pull images from ECR, send logs to CloudWatch, or retrieve the password from AWS Secrets Manager. This task execution role is performed before your container enters the running state.

Who use it?

The ECS agent uses it, not your application code.

When is it used?

Before container even starts running.

What is it for?

  1. Pull images from Amazon Elastic Container Registry (ECR)

  2. Send container logs to Amazon CloudWatch

  3. Retrieve secrets from AWS Secrets Manager

  4. Retrieve parameters from AWS Systems Manager

ECS Task role

My application code (business logic) needs to upload PDF files to AWS S3, store tracking info in Amazon DynamoDB, and push notifications from Amazon SNS. The ECS task role is not used by the ECS agent, this role is only used by your application code inside the container. If the task role is miss your application is run but can't access AWS API calls.

Who use it?

My application code inside the container.

When is it used?

After the container start running.

What is it for?

To allow my application to access AWS services.

Examples:

  1. Read/write to Amazon S3

  2. Send messages to Amazon Simple Queue Service

  3. Publish to Amazon Simple Notification Service

  4. Access Amazon DynamoDB

  5. Call other AWS APIs

I hope you understand the difference between a task role and an execution role in AWS ECS.