Granting EC2 Access to CodeArtifact for Python Packages
A company uses an AWS CodeArtifact repository to store Python packages that the company developed internally. A DevOps engineer needs to use AWS CodeDeploy to deploy an application to an Amazon EC2 instance. The application uses a Python package that is stored in the CodeArtifact repository. A BeforeInstall lifecycle event hook will install the package. The DevOps engineer needs to grant the EC2 instance access to the CodeArtifact repository. Which solution will meet this requirement?
Community Insight
The exam tests knowledge of CodeArtifact's specific authentication model: it relies on IAM permissions attached to the executing principal (via Instance Profile) and the
aws codeartifact logincommand, rather than resource-based policies or service-linked roles.
This question tests the correct method for an EC2 instance to authenticate with AWS CodeArtifact using IAM roles and the codeartifact login CLI. It establishes that resource-based policies are not supported for CodeArtifact repositories.
Candidates often select Option B, assuming CodeArtifact supports resource-based policies like S3 buckets. This is incorrect because CodeArtifact access is controlled entirely through IAM identity-based policies.
Community Discussion (8 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
Option D is the only valid solution. To allow an EC2 instance to access CodeArtifact, you must attach an IAM role with appropriate permissions to the instance via an Instance Profile. Theaws codeartifact login command then uses the temporary credentials from this role to configure the package manager (e.g., pip) with an authorization token. This is the standard, secure way to integrate CodeArtifact with compute services.Why the Other Options Are Wrong
Option A is incorrect because CodeArtifact does not use a service-linked role for client access; it requires specific IAM permissions. Option B is incorrect because CodeArtifact repositories do not support resource-based policies; access is strictly identity-based. Option C is incorrect because CodeArtifact does not use ACLs in the traditional sense (like S3); it relies on IAM policies.Community Comment Notes
Community consensus strongly favors Option D. Users like 'uncledana' and 'Srikantha' correctly identify that IAM roles andcodeartifact login are required. User 'nickp84' explicitly notes that CodeArtifact does not support resource-based policies, debunking Option B. While some users initially considered resource policies, official documentation confirms they are not applicable here. Official Reference
Exam Strategy
Always verify if a service supports resource-based policies. For CodeArtifact, remember that access is managed via IAM identity-based policies attached to the user, role, or instance profile performing the action.
Frequently Asked Questions
Does CodeArtifact support resource-based policies?
No. CodeArtifact access is controlled entirely through IAM identity-based policies attached to users, roles, or instance profiles.
What is the purpose of aws codeartifact login?
It configures your package manager (like pip) to use temporary credentials from the instance's IAM role to authenticate with CodeArtifact.
Related Analysis
Practice All DOP-C02 Questions
Access 85 questions with complete answers and detailed explanations.
View Full DOP-C02 Practice Test →