Add Lambda versioning and alias support#2173
Conversation
jaeyoung0509
left a comment
There was a problem hiding this comment.
Thanks for putting this together. 🎉
I left one small UX question inline, but overall this looks like a solid foundation for SnapStart support.
| @property | ||
| def lambda_alias(self) -> Optional[str]: | ||
| return self._chain_lookup('lambda_alias', | ||
| varies_per_chalice_stage=True, | ||
| varies_per_function=True) | ||
|
|
There was a problem hiding this comment.
-
One small UX question: should
lambda_aliasbe validated somewhere in the config validation path against Lambda alias naming constraints? -
For example, Chalice could reject values like
$LATEST, numeric-only aliases, empty strings, or names containing unsupported characters before deployment. That might give users a clearer Chalice-level error instead of surfacing a lower-level Lambda API error later.
There was a problem hiding this comment.
+1 -> A validation function similar to the ones in validate.py would work well here.
| FunctionName=function_name | ||
| ) | ||
| except lambda_client.exceptions.ResourceConflictException: | ||
| result = self._latest_published_function_version(function_name) |
There was a problem hiding this comment.
When ResourceConflictException is caught, _latest_published_function_version would return the version form the previous deploy. Instead of using the latest published version when there's a conflict, is it possible to add a delay, similar how its done here?
| @property | ||
| def lambda_alias(self) -> Optional[str]: | ||
| return self._chain_lookup('lambda_alias', | ||
| varies_per_chalice_stage=True, | ||
| varies_per_function=True) | ||
|
|
There was a problem hiding this comment.
+1 -> A validation function similar to the ones in validate.py would work well here.
Related: #20, #24, #2147
Overview
This PR adds Lambda versioning and alias support through a new
lambda_aliasconfig option. When configured, Chalice publishes a Lambda version after updating$LATEST, creates or updates the configured alias, and routes Chalice-managed integrations through the alias ARN. This gives apps a stable, versioned invocation target while keeping the behavior opt-in.The implementation supports direct deploys as well as generated SAM and Terraform templates. SAM templates use
AutoPublishAliaswithAutoPublishAliasAllProperties, and Terraform templates publish function versions and createaws_lambda_aliasresources. The same config can be set globally, per stage, or per function.Removing
lambda_aliasstops Chalice from publishing versions and updating the alias. On the next direct deploy, managed integrations move back to the unqualified function ARN, but Chalice does not delete the existing Lambda alias from AWS. For packaged deployments, the generated template no longer includes the alias resource.Testing
Deployed a new
helloworldproject with"lambda_alias": "live"and validated that versioning and alias support worked as expected.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.