Skip to content
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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
Address PR Comments
  • Loading branch information
driverpt committed Jan 30, 2025
commit 6d8882dcd83c2071e2c6f21cd1d746be6f211b0f
30 changes: 15 additions & 15 deletions samcli/lib/sync/flows/alias_version_sync_flow.py
Original file line number Diff line number Diff line change
@@ -27,15 +27,15 @@ class AliasVersionSyncFlow(SyncFlow):
_lambda_client: Any

def __init__(
self,
function_identifier: str,
alias_name: str,
delete_old_alias: bool,
build_context: "BuildContext",
deploy_context: "DeployContext",
sync_context: "SyncContext",
physical_id_mapping: Dict[str, str],
stacks: Optional[List[Stack]] = None,
self,
function_identifier: str,
alias_name: str,
delete_old_alias: bool,
build_context: "BuildContext",
deploy_context: "DeployContext",
sync_context: "SyncContext",
physical_id_mapping: Dict[str, str],
stacks: Optional[List[Stack]] = None,
):
"""
Parameters
@@ -102,9 +102,9 @@ def sync(self) -> None:
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)

formatted_function_name_version = "{}:{}".format(function_physical_id, current_alias_version)
LOG.debug("%Deleting Old Version Alias: %s", self.log_prefix, current_alias_version)
self._lambda_client.delete_function(FunctionName=formatted_function_name_version)

def gather_dependencies(self) -> List[SyncFlow]:
return []
@@ -119,7 +119,7 @@ def _equality_keys(self) -> Any:
def _get_version_alias_if_exists(self) -> Optional[str]:
try:
return str(self._lambda_client.get_alias(FunctionName=self.get_physical_id(self._function_identifier),
Name=self._alias_name)
.get("FunctionVersion"))
Name=self._alias_name)
.get("FunctionVersion"))
except self._lambda_client.exceptions.ResourceNotFoundException:
return None
return None