A developer is deploying a Python application to Amazon ECS on AWS Fargate. The application uses the AWS SDK for Python (Boto3) to upload objects to an Amazon S3 bucket. During local testing, the developer initialized the S3 client by passing a specific profile name from their local AWS CLI configuration file. In production, the Fargate task is assigned an ECS Task Role with the required S3 permissions, but the application fails to start due to a client initialization error. Which action should the developer take to resolve this issue?
- AAttach the required S3 permission policy to the ECS Task Execution Role instead of the Task Role, and configure the Boto3 client to request credentials from the task execution environment variables.
- BRetrieve the access keys and session token of the developer's IAM user, and pass them as hardcoded string arguments when initializing the Boto3 client in the application code.
- Initialize the S3 client using the default constructor (for example, `boto3.client('s3')`) without specifying any profile name or credentials, allowing the SDK to use the default credential provider chain to retrieve credentials from the ECS container.Cevap
- DStore the developer's IAM credentials in AWS Systems Manager Parameter Store as a secure string, and configure the application code to retrieve these credentials at startup to initialize the Boto3 client.
Cevap
Initialize the S3 client using the default constructor without specifying any profile name or credentials, allowing the SDK to use the default credential provider chain to retrieve credentials from the ECS container.
Initializing the S3 client using the default constructor (for example, `boto3.client('s3')`) allows the AWS SDK to use the default credential provider chain. In an ECS container environment on AWS Fargate, this chain automatically retrieves temporary credentials via the ECS container agent using the ECS Task Role. This eliminates the need to specify a profile name (which is only present in the developer's local AWS CLI configuration) or to manage static credentials in code.
Adım Adım Çözüm
Anahtar Kavram
AWS SDK Default Credential Provider Chain and ECS Task Roles