How do I clean up unused AWS SAM artifacts in my S3 bucket?
Asked by
CuriousCloud123
I've been deploying my AWS SAM application multiple times, and the artifacts are piling up in the managed S3 bucket. It's become massive, and I'm not sure which files I can safely delete. I'd like to set a lifecycle rule but I don't want to risk deleting anything that might still be in use, like resources linked to Lambda functions through `CodeUri`. Has anyone figured out an effective way to manage or automate this cleanup?
Answers
You could consider writing a shell script that uses the AWS CLI to check for unused artifacts. Itโs not perfect, but it might streamline the process for you!
Reply to this answer
I get that it looks messy, but are you really spending that much on storage? If the objects are small, it might just be a few cents a monthโprobably not worth the hassle of sorting through them all.
CuriousCloud123: Actually, they are costing me. Itโs already hit over 10GB, which is why Iโm trying to clean this up.
Reply to this answer
In most cases, you can delete everything except maybe the latest few artifacts. AWS SAM will automatically re-upload whatโs needed on the next deploy. Just keep a recent batch in case of rollbacks.
CuriousCloud123: That's the main concern for meโI'm looking for a way to remove things not referenced anywhere without having to check them all manually.
Reply to this answer
Add your answer
Answers are reviewed before publication.
GentleCodeFreak: What do you mean by checking? Are you suggesting we should do reference counting for AWS SAM?