I've noticed that during every deployment, AWS SAM uploads artifacts to a managed S3 bucket, and now it has ballooned in size. I'm unsure about what I can safely delete using a lifecycle rule because I would need to check each AWS resource to determine if it's referenced, like checking the `CodeUri` for Lambda functions. With thousands of objects in this bucket, I'm looking for a way to clean it up without going through each one manually. Has anyone tackled this issue?
3 Answers
I get that it looks cluttered, but are they really costing you that much? From what I see, if the objects are quite small, it might just add up to a few cents each month, which isn't worth the hassle of sorting through them. Just keep in mind that standard-tier objects incur minimal fees unless you access them.
Generally, you can probably delete most of the artifacts in your bucket, keeping just the most recent ones as a backup for CloudFormation rollbacks. SAM will re-upload what it needs during your next deployment, so you don’t need to worry too much about losing anything important.
That's kind of my main concern—I'm hoping for a way to delete unreferenced items without needing to manually verify each one. It feels like a tedious process!
You might want to consider writing a shell script that utilizes the AWS CLI to help you check which artifacts are safe to delete. It could automate some of the referencing process for you!
But what exactly are you suggesting to check? Are you proposing to do reference counting for AWS SAM?

Actually, they are costing me quite a bit already—over 10GB in total! That’s why I want to tackle this issue. The aesthetics don’t really bother me; it’s the cost that does!