-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds support to delete old versions when successful deployment #7414
base: develop
Are you sure you want to change the base?
Conversation
788b91b
to
f414471
Compare
f414471
to
26d1e47
Compare
Hi, Thanks for bringing up this PR. The code looks good to me so Ill run the approval workflow to get the testing process started, but can you also create an integration tests testing the happy path from beginning to end? |
Can you also run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this PR, left some comments. Additionally, we might want to consider adding this to the sam deploy
command. This might need some more thought though if this makes sense to you and the team.
@@ -109,11 +109,13 @@ def gather_dependencies(self) -> List[SyncFlow]: | |||
raise FunctionNotFound(f"Unable to find function {self._function_identifier}") | |||
|
|||
auto_publish_alias_name = function_resource.get("Properties", dict()).get("AutoPublishAlias", None) | |||
auto_delete_old_alias = function_resource.get("Properties", dict()).get("AutoDeleteOldAlias", False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a new property for the AWS::Serverless::Function
. This will require a SAM spec change if we wanted to use it like this.
Since deleting old Lambda versions is something that is being implemented as SAM CLI specific behaviour, placing it inside of the Metadata
part of the function inside the template might be a better location.
I can also bring this up with the team about the best way to go about triggering the delete behaviour.
version = self._lambda_client.publish_version(FunctionName=function_physical_id).get("Version") | ||
self._local_sha = str_checksum(str(version), hashlib.sha256()) | ||
LOG.debug("%sCreated new function version: %s", self.log_prefix, version) | ||
if version: | ||
self._lambda_client.update_alias( | ||
FunctionName=function_physical_id, Name=self._alias_name, FunctionVersion=version | ||
) | ||
if self._delete_old_alias and current_alias_version: | ||
function_name_w_version = "{}:{}".format(function_physical_id, current_alias_version) | ||
self._lambda_client.delete_function(FunctionName=function_name_w_version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it ever be possible for this to be my_function:$LATEST
? Just wanted to ask what happens if the Lambda alias resolved to the latest version of the function, and if deleting my_function:$LATEST
just deletes the function.
version = self._lambda_client.publish_version(FunctionName=function_physical_id).get("Version") | ||
self._local_sha = str_checksum(str(version), hashlib.sha256()) | ||
LOG.debug("%sCreated new function version: %s", self.log_prefix, version) | ||
if version: | ||
self._lambda_client.update_alias( | ||
FunctionName=function_physical_id, Name=self._alias_name, FunctionVersion=version | ||
) | ||
if self._delete_old_alias and current_alias_version: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a log message here? This is deleting something, so we'll want to let people know that an old version is now being deleted.
version = self._lambda_client.publish_version(FunctionName=function_physical_id).get("Version") | ||
self._local_sha = str_checksum(str(version), hashlib.sha256()) | ||
LOG.debug("%sCreated new function version: %s", self.log_prefix, version) | ||
if version: | ||
self._lambda_client.update_alias( | ||
FunctionName=function_physical_id, Name=self._alias_name, FunctionVersion=version | ||
) | ||
if self._delete_old_alias and current_alias_version: | ||
function_name_w_version = "{}:{}".format(function_physical_id, current_alias_version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: changing _w_
to _with_
, or renaming to something like formatted_function_name_version
for future contributors that are not familiar with the "with" shorthand
Which issue(s) does this change fix?
#7398
Why is this change necessary?
Because there's a limit on how many versions a Lambda has.
How does it address the issue?
Automatically deletes old version. Very useful when on SnapStart
What side effects does this change have?
None, it's disabled by default
Mandatory Checklist
PRs will only be reviewed after checklist is complete
make pr
passesmake update-reproducible-reqs
if dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.