# Version

Tag the current state of a Function with a Version number.

Avoid using this resource directly. If you need a Version object, use
`function.currentVersion` instead. That will add a Version object to your
template, and make sure the Version is invalidated whenever the Function
object changes. If you use the `Version` resource directly, you are
responsible for making sure it is invalidated (by changing its
logical ID) whenever necessary.

Version resources can then be used in `Alias` resources to refer to a
particular deployment of a Lambda.

If you want to ensure that you're associating the right version with
the right deployment, specify the `codeSha256` property while
creating the `Version.

Extends: Construct › Resource › FunctionBase › QualifiedFunctionBase › Version
Implements: IResource, IClientVpnConnectionHandler, IConnectable, IGrantable, IFunction, IVersion, IEnvironmentAware, IFunctionRef, IVersionRef, IConstruct, IDependable

- CloudFormation: [`AWS::Lambda::Version`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-lambda-version.html)
- L1 type: [`CfnVersion`](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.CfnVersion.html)
- Source: [`aws-lambda/lib/lambda-version.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-lambda/lib/lambda-version.ts#L143)
- Type last changed: v2.224.0 · 13 Nov 2025

## Example

```ts
const lambdaCode = lambda.Code.fromCfnParameters();
const func = new lambda.Function(this, 'Lambda', {
  code: lambdaCode,
  handler: 'index.handler',
  runtime: lambda.Runtime.NODEJS_LATEST,
});
// used to make sure each CDK synthesis produces a different Version
const version = func.currentVersion;
const alias = new lambda.Alias(this, 'LambdaAlias', {
  aliasName: 'Prod',
  version,
});

new codedeploy.LambdaDeploymentGroup(this, 'DeploymentGroup', {
  alias,
  deploymentConfig: codedeploy.LambdaDeploymentConfig.LINEAR_10PERCENT_EVERY_1MINUTE,
});
```

## Initializer

```ts
new Version(scope: Construct, id: string, props: VersionProps)
```

## Construct Props

- `codeSha256`: string — SHA256 of the version of the Lambda source code.

  **Default:** No validation is performed

  Specify to validate that you're deploying the right version.

- `description`: string — Description of the version.

  **Default:** Description of the Lambda

- `lambda`: [IFunction](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IFunction.html) (required) — Function to get the value of.

- `maxEventAge`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = Duration.hours(6) — The maximum age of a request that Lambda sends to a function for processing.

  Minimum: 60 seconds
  Maximum: 6 hours

- `maxExecutionEnvironments`: number — The maximum number of execution environments allowed for this version when published into a capacity provider.

  **Default:** No maximum specified

  This setting limits the total number of execution environments that can be created
  to handle concurrent invocations of this specific version.

- `minExecutionEnvironments`: number — The minimum number of execution environments to maintain for this version when published into a capacity provider.

  **Default:** 3 execution environments are set to be the minimum

  This setting ensures that at least this many execution environments are always
  available to handle function invocations for this specific version, reducing cold start latency.

- `onFailure`: [IDestination](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IDestination.html) — The destination for failed invocations.

  **Default:** no destination

- `onSuccess`: [IDestination](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IDestination.html) — The destination for successful invocations.

  **Default:** no destination

- `provisionedConcurrentExecutions`: number — Specifies a provisioned concurrency configuration for a function's version.

  **Default:** No provisioned concurrency

- `removalPolicy`: [RemovalPolicy](/cdk/api/v2/docs/aws-cdk-lib.RemovalPolicy.html) = RemovalPolicy.DESTROY — Whether to retain old versions of this function when a new version is created.

- `retryAttempts`: number = 2 — The maximum number of times to retry when the function returns an error.

  Minimum: 0
  Maximum: 2

## Properties

- `architecture`: [Architecture](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Architecture.html) — The architecture of this Lambda Function.

- `connections`: [Connections](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Connections.html) — Access the Connections object.

  Will fail if not a VPC-enabled Lambda Function

- `edgeArn`: string — The ARN of the version for Lambda@Edge.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `functionArn`: string — The ARN fo the function.

- `functionName`: string — The name of the function.

- `functionRef`: [FunctionReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_lambda.FunctionReference.html) — A reference to a Function resource.

- `grantPrincipal`: [IPrincipal](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IPrincipal.html) — The principal this Lambda Function is running as.

- `isBoundToVpc`: boolean — Whether or not this Lambda function was bound to a VPC.

  If this is `false`, trying to access the `connections` object will fail.

- `lambda`: [IFunction](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IFunction.html) — The underlying `IFunction`.

- `latestVersion`: [IVersion](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IVersion.html) — The `$LATEST` version of this function.

  Note that this is reference to a non-specific AWS Lambda version, which
  means the function this version refers to can return different results in
  different invocations.

  To obtain a reference to an explicit version which references the current
  function configuration, use `lambdaFunction.currentVersion` instead.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `permissionsNode`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The construct node where permissions are attached.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `resourceArnsForGrantInvoke`: string[] — The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().

- `role`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM role associated with this function.

  Undefined if the function was imported without a role.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this resource is defined.

- `tenancyConfig`: [TenancyConfig](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.TenancyConfig.html) — The tenancy configuration for this function.

- `version`: string — The most recently deployed version of this function.

- `versionRef`: [VersionReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_lambda.VersionReference.html) — A reference to a Version resource.

## Methods

- `addAlias(aliasName: string, options?: AliasOptions): Alias` — Calling `addAlias` on a `Version` object will cause the Alias to be replaced on every function update. Call `function.addAlias()` or `new Alias()` instead.

  **Parameters**

  - `aliasName` — The name of the alias (e.g. "live").
  - `options` — Alias options.

- `addEventSource(source: IEventSource): void` — Adds an event source to this function.

  Event sources are implemented in the aws-cdk-lib/aws-lambda-event-sources module.

  The following example adds an SQS Queue as an event source:
  ```
  import { SqsEventSource } from 'aws-cdk-lib/aws-lambda-event-sources';
  myFunction.addEventSource(new SqsEventSource(myQueue));
  ```

- `addEventSourceMapping(id: string, options: EventSourceMappingOptions): EventSourceMapping` — Adds an event source that maps to this AWS Lambda function.

- `addFunctionUrl(options?: FunctionUrlOptions): FunctionUrl` — Adds a url to this lambda function.

- `addPermission(id: string, permission: Permission): void` — Adds a permission to the Lambda resource policy.

  **Parameters**

  - `id` — The id for the permission construct.
  - `permission` — The permission to grant to this Lambda function.

- `addToRolePolicy(statement: PolicyStatement): void` — Adds a statement to the IAM role assumed by the instance.

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `configureAsyncInvoke(options: EventInvokeConfigOptions): void` — Configures options for asynchronous invocation.

- `considerWarningOnInvokeFunctionPermissions(_scope: Construct, _action: string): void` — A warning will be added to functions under the following conditions: - permissions that include `lambda:InvokeFunction` are added to the unqualified function.

  - function.currentVersion is invoked before or after the permission is created.

  This applies only to permissions on Lambda functions, not versions or aliases.
  This function is overridden as a noOp for QualifiedFunctionBase.

- `fromVersionArn(scope: Construct, id: string, versionArn: string): IVersion` (static) — Construct a Version object from a Version ARN.

  **Parameters**

  - `scope` — The cdk scope creating this resource.
  - `id` — The cdk id of this resource.
  - `versionArn` — The version ARN to create this version from.

- `fromVersionAttributes(scope: Construct, id: string, attrs: VersionAttributes): IVersion` (static)

- `grantInvoke(grantee: IGrantable): Grant` — Grant the given identity permissions to invoke this Lambda.

  [disable-awslint:no-grants]

- `grantInvokeCompositePrincipal(compositePrincipal: CompositePrincipal): Grant[]` — Grant multiple principals the ability to invoke this Lambda via CompositePrincipal.

  [disable-awslint:no-grants]

- `grantInvokeLatestVersion(grantee: IGrantable): Grant` — Grant the given identity permissions to invoke the $LATEST version or unqualified version of this Lambda.

  [disable-awslint:no-grants]

- `grantInvokeUrl(grantee: IGrantable): Grant` — Grant the given identity permissions to invoke this Lambda Function URL.

  [disable-awslint:no-grants]

- `grantInvokeVersion(grantee: IGrantable, version: IVersion): Grant` — Grant the given identity permissions to invoke the given version of this Lambda.

  [disable-awslint:no-grants]

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `metric(metricName: string, props?: MetricOptions): Metric` — Return the given named metric for this Function.

- `metricDuration(props?: MetricOptions): Metric` — How long execution of this Lambda takes.

  Average over 5 minutes

- `metricErrors(props?: MetricOptions): Metric` — How many invocations of this Lambda fail.

  Sum over 5 minutes

- `metricInvocations(props?: MetricOptions): Metric` — How often this Lambda is invoked.

  Sum over 5 minutes

- `metricThrottles(props?: MetricOptions): Metric` — How often this Lambda is throttled.

  Sum over 5 minutes

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
