How to create a new version of a Lambda function using CloudFormation?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In CloudFormation, you create a published Lambda version with the AWS::Lambda::Version resource. The usual pattern is to define the function as AWS::Lambda::Function, then add a version resource that points at that function, and optionally point an alias at the published version.
The important detail is that Lambda versions are immutable. CloudFormation will only create a meaningful new version when the function code or relevant version-triggering configuration has changed, or when the version resource itself is forced to change.
Define the Function and the Version
A basic template looks like this:
When CloudFormation creates MyFunctionVersion, Lambda publishes an immutable version of the function state at that point.
Use an Alias for Stable Traffic Routing
Most real deployments also define an alias:
The alias gives clients a stable ARN such as live, while the published version number changes over time. This is much easier to operate than asking every downstream system to call version 17, then 18, then 19 directly.
Why a New Version Sometimes Does Not Appear
A common source of confusion is that updating the function resource does not always mean you get a new published version automatically. CloudFormation needs the version resource to resolve to a distinct publish action.
In practice, a new version is normally created when:
- the function code package changed
- version-relevant configuration changed
- the version resource is updated in a way that causes republishing
If you keep the exact same code and same effective version input, you should not expect a new meaningful immutable version to appear.
That is why deployment pipelines usually tie the code artifact key, hash, or version description to each release.
Make Version Creation Intentional
One helpful pattern is to include a release identifier in the version description or artifact location:
That makes the CloudFormation update intent clearer. It also helps humans understand which deployment a published version corresponds to. It is especially useful when a stack is updated frequently from CI and you need to correlate infrastructure changes with application releases.
Think in Terms of Function, Version, and Alias
The deployment model is easiest to reason about if you separate the three layers:
- function: mutable working definition
- version: immutable snapshot
- alias: stable pointer to a chosen version
Once you think this way, rollbacks and deployments become simpler. You publish a new version, then move the alias if the release is good.
Common Pitfalls
- Expecting
AWS::Lambda::Functionupdates alone to behave like immutable version publishing. - Forgetting that
AWS::Lambda::Versioncreates immutable snapshots, so old versions do not change. - Invoking raw version numbers directly when an alias would be easier to manage.
- Reusing the same artifact and metadata and then wondering why versioning behavior seems unchanged.
Summary
- Use
AWS::Lambda::Versionin CloudFormation to publish a Lambda version. - Point an
AWS::Lambda::Aliasat that version for stable invocation. - New versions are meaningful only when the function state or release inputs actually change.
- Treat function, version, and alias as three separate deployment concepts.
- Make release identity explicit so CloudFormation-driven versioning stays predictable.

