A developer is configuring an Amazon ECS task definition to deploy a microservice to AWS Fargate. The container image is stored in a private Amazon ECR repository. During startup, the containerized application must read database credentials from AWS Secrets Manager. The developer wants to inject these credentials as container environment variables without exposing them in plaintext or embedding them in the container image.
Which two actions should the developer take to configure the task definition and IAM roles for this deployment? (Select TWO.)
- Configure the ECS Task Execution Role with a policy that allows the secretsmanager:GetSecretValue action.Cevap
- In the container definition, use the secrets parameter to reference the database credential secret and map it to a container environment variable.Cevap
- CConfigure the ECS Task Role with a policy that allows the ecr:GetDownloadUrlForLayer and ecr:BatchGetImage actions.
- DConfigure the trust policy of the ECS Task Execution Role to trust the service principal ecs.amazonaws.com.
- EIn the container definition, specify the database credentials in plaintext within the environment parameter to pass them directly to the container.
Cevap
The correct configurations are to configure the ECS Task Execution Role with a policy that allows the secretsmanager:GetSecretValue action, and to reference the database credential secret using the secrets parameter in the container definition to map it to an environment variable.
The ECS agent is responsible for both pulling the container image from Amazon ECR and retrieving database credentials from Secrets Manager to inject them as environment variables during container creation. Therefore, these permissions must be granted to the ECS Task Execution Role, and the task definition container definition must use the secrets parameter to map the secret ARN to the desired environment variable name.
Adım Adım Çözüm
Anahtar Kavram
Distinction between ECS Task Role and ECS Task Execution Role, and secure injection of secrets into ECS containers.