Skip to content

Add Lambda versioning and alias support#2173

Draft
jonathan343 wants to merge 1 commit into
masterfrom
feat/versioning-aliases
Draft

Add Lambda versioning and alias support#2173
jonathan343 wants to merge 1 commit into
masterfrom
feat/versioning-aliases

Conversation

@jonathan343
Copy link
Copy Markdown
Collaborator

Related: #20, #24, #2147

Overview

This PR adds Lambda versioning and alias support through a new lambda_alias config 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 AutoPublishAlias with AutoPublishAliasAllProperties, and Terraform templates publish function versions and create aws_lambda_alias resources. The same config can be set globally, per stage, or per function.

Removing lambda_alias stops 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 helloworld project 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.

Copy link
Copy Markdown

@jaeyoung0509 jaeyoung0509 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together. 🎉
I left one small UX question inline, but overall this looks like a solid foundation for SnapStart support.

Comment thread chalice/config.py
Comment on lines +346 to +351
@property
def lambda_alias(self) -> Optional[str]:
return self._chain_lookup('lambda_alias',
varies_per_chalice_stage=True,
varies_per_function=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • One small UX question: should lambda_alias be 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 -> A validation function similar to the ones in validate.py would work well here.

Comment thread chalice/awsclient.py
FunctionName=function_name
)
except lambda_client.exceptions.ResourceConflictException:
result = self._latest_published_function_version(function_name)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread chalice/config.py
Comment on lines +346 to +351
@property
def lambda_alias(self) -> Optional[str]:
return self._chain_lookup('lambda_alias',
varies_per_chalice_stage=True,
varies_per_function=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 -> A validation function similar to the ones in validate.py would work well here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants