A developer is deploying a containerized application to Amazon ECS using AWS Fargate. During task startup, the container fails to launch. The ECS service events reveal that the task is unauthorized to pull the application image from Amazon Elastic Container Registry (ECR). In addition, the container is configured to retrieve a database secret from AWS Secrets Manager at startup, which is also failing. The developer verifies that the IAM policy attached to the ECS Task Role (task_role_arn) has the necessary ecr:GetDownloadUrlForLayer, ecr:BatchGetImage, and secretsmanager:GetSecretValue permissions.
What action should the developer take to resolve these authorization failures?
- AConfigure an Amazon Cognito Identity Pool to exchange temporary credentials during task initialization.
- BUpdate the trust policy of the ECS Task Role to allow the Secrets Manager service principal (secretsmanager.amazonaws.com) to assume the role.
- CEmbed the ECR registry credentials and Secrets Manager secrets directly inside the application's source code.
- Attach the required permissions to the ECS Task Execution Role instead of the ECS Task Role.Cevap
Cevap
Attach the required permissions to the ECS Task Execution Role instead of the ECS Task Role.
The Amazon ECS container agent makes the API calls to pull the container image from Amazon ECR and to retrieve secrets from AWS Secrets Manager during the task bootstrap phase. These operations occur before the application container is running. Therefore, the permissions must be attached to the ECS Task Execution Role, not the ECS Task Role (which is used by the application code once running).
Adım Adım Çözüm
Anahtar Kavram
ECS Task Role vs. ECS Task Execution Role permissions