A developer is packaging a Node.js application to run in an Amazon ECS container on AWS Fargate. During local testing on developer workstations, the application accesses AWS resources using credentials retrieved from the AWS IAM Identity Center (via the AWS CLI `aws sso login` command). In the production Fargate environment, the application must access an Amazon DynamoDB table. The developer wants the application to automatically resolve the correct credentials in both environments using the AWS SDK's default credential provider chain without any code changes or hardcoded credentials.
Which two configuration actions must the developer take to meet these requirements?
- Assign the IAM role that has DynamoDB read/write permissions to the ECS Task Role (taskRoleArn) in the ECS task definition.Answer
- Set the AWS_PROFILE environment variable on local developer workstations to match the name of the IAM Identity Center profile configured in the shared AWS config file.Answer
- CAssign the IAM role that has DynamoDB read/write permissions to the ECS Task Execution Role (executionRoleArn) in the ECS task definition.
- DConfigure the IAM role's trust policy to allow the ec2.amazonaws.com service principal to assume the role.
- EConfigure the application to retrieve temporary credentials from AWS Systems Manager Parameter Store and initialize the SDK client directly with those credentials.
Answer
Assigning the IAM role with DynamoDB access to the Task Role (taskRoleArn) in the task definition, and setting the AWS_PROFILE environment variable on local developer workstations to match the name of the IAM Identity Center profile in the shared AWS configuration file.
The correct configurations involve using the ECS Task Role (taskRoleArn) to delegate application permissions in Fargate, and setting the AWS_PROFILE environment variable locally to direct the SDK's default credential provider chain to the correct SSO profile in the shared AWS configuration file. This allows the application code to remain environment-agnostic, resolving credentials automatically using the default provider chain.
Step-by-Step Solution
Key Concept
AWS SDK Default Credential Provider Chain and Container Credential Resolution