DOP-C02 Question 54
Single answerYour team uses AWS CodePipeline to automate the build and deployment process. During a recent audit, it was found that old build artifacts stored in Amazon S3 are not being managed properly, leading to increased storage costs. You want to implement an automated solution to ensure that only the last 20 successful build artifacts are retained, while ensuring compliance with your organization's data retention policies. What is the best approach to achieve this?
- A
Configure an S3 Lifecycle policy to delete artifacts older than 30 days.
- B
Write an AWS Lambda function triggered by Amazon S3 events to delete artifacts exceeding the retention limit of 20.
- C
Utilize the AWS CodeBuild buildspec file to automatically delete old artifacts after each build completes.
- D
Use AWS Systems Manager Automation documents to clean up old artifacts on a scheduled basis.
Show answer and explanation
Correct answer: B
Explanation
The best approach to manage the lifecycle of build artifacts in this scenario is to use an AWS Lambda function triggered by Amazon S3 events. This allows for implementing custom logic to track and delete artifacts that exceed the retention limit of 20, ensuring compliance with your organization's retention policies. S3 Lifecycle policies and other options do not provide the necessary flexibility to retain a specific number of artifacts based on success criteria.
- A. Incorrect.
Configuring an S3 Lifecycle policy based on object age (e.g., 30 days) is not ideal for retaining only the last 20 successful build artifacts, as it does not account for the number of retained artifacts but rather their age.
- B. Correct.
Using an AWS Lambda function triggered by S3 events provides a flexible mechanism to track and delete artifacts exceeding the retention limit of 20. This approach allows you to implement custom logic to manage the artifact lifecycle effectively.
- C. Incorrect.
The AWS CodeBuild buildspec file is used for configuring build and test commands, but it does not provide functionality to manage or delete historical build artifacts.
- D. Incorrect.
AWS Systems Manager Automation documents (SSM documents) are designed for operational tasks but are not ideal for managing specific S3 objects, such as build artifacts.