A developer has deployed a containerized Node.js application inside a Docker container running on an Amazon EC2 instance. The application uses the AWS SDK for JavaScript to query an Amazon DynamoDB table. An IAM role with the necessary permissions is attached to the EC2 instance via an IAM instance profile. The EC2 instance is configured to require Instance Metadata Service Version 2 (IMDSv2).
While the application successfully accesses DynamoDB when executed directly on the EC2 host, it fails with a credential initialization error when running inside the Docker container. The container is running on the default bridge network.
Which of the following actions should the developer take to resolve this credential issue? (Select TWO.)
- Modify the EC2 instance metadata options to increase the response hop limit to 2 or more.Answer
- Run the Docker container using host network mode by specifying the `--network host` flag.Answer
- CGenerate static IAM access keys for the EC2 instance profile role and pass them as environment variables to the container.
- DConfigure the container environment with the `AWS_ROLE_ARN` environment variable set to the ARN of the EC2 instance profile's IAM role.
- EDisable IMDSv2 on the EC2 instance and fallback to IMDSv1 to bypass the token request requirements.
Answer
To resolve the credential issue, the developer must either modify the EC2 instance metadata options to increase the response hop limit to 2 or more, or run the Docker container in host network mode using the `--network host` flag.
The credential retrieval failure is caused by the default IMDSv2 response hop limit of 1. When a container runs on the default bridge network, any traffic to the link-local metadata address must cross the container bridge, which counts as an IP hop. Consequently, the metadata response is dropped. The correct actions are to increase the metadata response hop limit to 2 or more on the EC2 instance, or to run the container using host network mode, which eliminates the bridge hop entirely.
Step-by-Step Solution
Key Concept
IMDSv2 Metadata Response Hop Limit in Containerized Environments