Skip to content

CodeArtifact Automated Cleanup

0

I am working on moving our locally-hosted (but in AWS) maven artifact repository to CodeArtifact. We have scheduled tasks configured for old/obsolete artifact cleanup. Is there built-in functionality similar to this for CodeArtifact? The only thing I am finding in documentation is using AWS CLI or the console: https://docs.aws.amazon.com/codeartifact/latest/ug/delete-package.html.

asked 2 years ago838 views

1 Answer
0

AWS CodeArtifact does not currently offer built-in automated cleanup functionality for old or obsolete artifacts. The primary methods for deleting packages and package versions in CodeArtifact are indeed through the AWS CLI or the AWS Management Console, as you've found in the documentation.

However, you can create a custom solution to automate the cleanup process using AWS services. Here's an approach you could consider:

  1. Use AWS Lambda to create a function that executes the necessary AWS CLI commands to delete old packages or package versions.

  2. Schedule this Lambda function using Amazon EventBridge (formerly CloudWatch Events) to run at your desired intervals, mimicking your current scheduled tasks.

  3. The Lambda function can use the delete-package or delete-package-versions CLI commands to remove old artifacts based on your defined criteria (e.g., age, version number, or other metadata).

  4. You can also use the DisposePackageVersions API, which deletes the assets in package versions and sets their status to 'Disposed'. This is particularly useful for permanent deletion, as disposed package versions cannot be restored.

  5. To identify which packages to delete, you can use the ListPackageVersions API to get a list of all package versions, potentially filtering by status.

While this approach requires some initial setup, it allows you to customize the cleanup process to your specific needs and automate it in a way that's similar to your current locally-hosted solution.

Remember to thoroughly test any automated deletion scripts in a non-production environment first, as deleting packages or versions in CodeArtifact is a permanent action and cannot be undone.

Sources
Delete a package or package version - CodeArtifact
DisposePackageVersions - AWS CodeArtifact

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.