aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

Tracking and Managing deployed lambda packages on S3 backup #1715

Open richard-moss opened 4 years ago

richard-moss commented 4 years ago

Hi there,

Summary

Is there a way to 'manage' deployed layer/function packages in S3 that have been deployed via SAM?

By manage: a) view which packages are 'stale' (new versions have been deployed and the old ones are now orphaned) b) in SAM CLI, and/or AWS CLI and/or AWS UI view for a particular lambda or layer which S3 package it is using?

When using SAM, my S3 bucket is filling up with deployment packages, and I'm not sure to see which ones are safe to delete (they are orphaned) and which ones are current?

Background

I've been using SAM for a few months now to develop some lambda deployments of an existing python function, which is working fairly well.

Due to my function design (which has a single lambda spawn multiple child lambda to wait for responses, all coupled with a custom layer), plus likely my newbie'nish with SAM and AWS in general, I've been doing a lot of the dev work directly on AWS, as I can't seem to get it to run locally via SAM.

The result is my S3 bucket I'm using for the deployment packages now has many, many packages placed there by sam deploy, but never purged.

I'd like to be able to remove orphaned packages from older deploy's.

thanks, Richard

jfuss commented 4 years ago

This sounds similar to https://github.com/awslabs/aws-sam-cli/issues/1070

richard-moss commented 4 years ago

Thanks! ...it's similiar in underlying problem I thnk, but perhaps a different approach.

The OP in #1070 sounded like 'managing' the deployed S3 packages was root issue. His idea was to be able to tag the packages to identify which lambda/layer they belong to.

I was thinking in the reverse - from examining the lambda's/layers how do you identify which packages they use? My thinking was that way at least I could write a simple script to walk the S3 bucket and delete orphaned packages, by first finding the set of currently referenced packages and using that as an exclusion list.

tmclaugh commented 2 years ago

I'm looking for something similar. I'd like to write a lifecycle rule on our S3 bucket that will expire packages from feature branches. We already standardly tag everything else with the branch name.