A developer is containerizing a Python microservice that uses the AWS SDK (Boto3) to retrieve objects from an Amazon S3 bucket. During local development on a macOS host, the developer runs the application in a Docker container using Docker Desktop. The container fails to authenticate with AWS and throws a `NoCredentialsError`. The host machine's AWS CLI is configured with a default profile and a named profile `local-dev` that contains active credentials.
Which TWO actions should the developer perform to resolve this authentication failure and allow the containerized application to use the `local-dev` credentials? (Choose two.)
- Mount the host machine's ~/.aws directory to the home directory of the user running inside the container (e.g., /root/.aws) and set the AWS_PROFILE environment variable to local-dev in the container runtime environment.Cevap
- Pass the AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN environment variables from the host's active shell session directly into the container using container runtime environment flags.Cevap
- CHardcode the AWS Access Key ID and Secret Access Key from the local-dev profile directly into the initialization code of the S3 client using Boto3 parameters.
- DModify the trust policy of the S3 bucket's IAM Role to explicitly trust the local Docker Desktop daemon IP address and allow access from external hosts.
- EConfigure the S3 client to call AWS Secrets Manager inside the container to fetch the credentials dynamically without passing bootstrap keys.
Cevap
Mount the host machine's credentials directory while setting the profile environment variable, or pass the active shell credential environment variables to the container at runtime.
The correct options provide valid, secure mechanisms to supply credentials to a local container without exposing secrets. Mounting the host's credential directory (~/.aws) into the container's user directory combined with the profile variable allows the SDK to resolve credentials from the configuration file. Alternatively, injecting active environment variables into the container environment allows the SDK's credential provider chain to resolve credentials from environment variables directly.
Adım Adım Çözüm
Anahtar Kavram
AWS SDK Default Credentials Provider Chain in Container Environments