Version — AWS Cloud Development Kit 1.204.0 documentation (original) (raw)

class aws_cdk.aws_lambda.Version(scope, id, *, lambda_, code_sha256=None, description=None, provisioned_concurrent_executions=None, removal_policy=None, max_event_age=None, on_failure=None, on_success=None, retry_attempts=None)

Bases: QualifiedFunctionBase

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

Avoid using this resource directly. If you need a Version object, usefunction.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.

ExampleMetadata:

infused

Example:

lambda_code = lambda_.Code.from_cfn_parameters() func = lambda_.Function(self, "Lambda", code=lambda_code, handler="index.handler", runtime=lambda_.Runtime.NODEJS_14_X )

used to make sure each CDK synthesis produces a different Version

version = func.current_version alias = lambda_.Alias(self, "LambdaAlias", alias_name="Prod", version=version )

codedeploy.LambdaDeploymentGroup(self, "DeploymentGroup", alias=alias, deployment_config=codedeploy.LambdaDeploymentConfig.LINEAR_10PERCENT_EVERY_1MINUTE )

Parameters:

Methods

add_alias(alias_name, *, additional_versions=None, description=None, provisioned_concurrent_executions=None, max_event_age=None, on_failure=None, on_success=None, retry_attempts=None)

(deprecated) Defines an alias for this version.

Parameters:

Deprecated:

Calling addAlias on a Version object will cause the Alias to be replaced on every function update. Call function.addAlias() or new Alias() instead.

Stability:

deprecated

Return type:

Alias

add_event_source(source)

Adds an event source to this function.

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

The following example adds an SQS Queue as an event source:

import { SqsEventSource } from '@aws-cdk/aws-lambda-event-sources'; myFunction.addEventSource(new SqsEventSource(myQueue));

Parameters:

source (IEventSource)

Return type:

None

add_event_source_mapping(id, *, batch_size=None, bisect_batch_on_error=None, enabled=None, event_source_arn=None, kafka_bootstrap_servers=None, kafka_topic=None, max_batching_window=None, max_record_age=None, on_failure=None, parallelization_factor=None, report_batch_item_failures=None, retry_attempts=None, source_access_configurations=None, starting_position=None, tumbling_window=None)

Adds an event source that maps to this AWS Lambda function.

Parameters:

Return type:

EventSourceMapping

add_function_url(*, auth_type=None, cors=None)

Adds a url to this lambda function.

Parameters:

Return type:

FunctionUrl

add_permission(id, *, principal, action=None, event_source_token=None, function_url_auth_type=None, scope=None, source_account=None, source_arn=None)

Adds a permission to the Lambda resource policy.

Parameters:

See:

Permission for details.

Return type:

None

add_to_role_policy(statement)

Adds a statement to the IAM role assumed by the instance.

Parameters:

statement (PolicyStatement)

Return type:

None

apply_removal_policy(policy)

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).

Parameters:

policy (RemovalPolicy)

Return type:

None

configure_async_invoke(*, max_event_age=None, on_failure=None, on_success=None, retry_attempts=None)

Configures options for asynchronous invocation.

Parameters:

Return type:

None

consider_warning_on_invoke_function_permissions(_scope, _action)

A warning will be added to functions under the following conditions: - permissions that include lambda:InvokeFunction are added to the unqualified function.

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

Parameters:

Return type:

None

grant_invoke(grantee)

Grant the given identity permissions to invoke this Lambda.

Parameters:

grantee (IGrantable)

Return type:

Grant

grant_invoke_url(grantee)

Grant the given identity permissions to invoke this Lambda Function URL.

Parameters:

grantee (IGrantable)

Return type:

Grant

metric(metric_name, *, account=None, color=None, dimensions=None, dimensions_map=None, label=None, period=None, region=None, statistic=None, unit=None)

Return the given named metric for this Function.

Parameters:

Return type:

Metric

metric_duration(*, account=None, color=None, dimensions=None, dimensions_map=None, label=None, period=None, region=None, statistic=None, unit=None)

How long execution of this Lambda takes.

Average over 5 minutes

Parameters:

Return type:

Metric

metric_errors(*, account=None, color=None, dimensions=None, dimensions_map=None, label=None, period=None, region=None, statistic=None, unit=None)

How many invocations of this Lambda fail.

Sum over 5 minutes

Parameters:

Return type:

Metric

metric_invocations(*, account=None, color=None, dimensions=None, dimensions_map=None, label=None, period=None, region=None, statistic=None, unit=None)

How often this Lambda is invoked.

Sum over 5 minutes

Parameters:

Return type:

Metric

metric_throttles(*, account=None, color=None, dimensions=None, dimensions_map=None, label=None, period=None, region=None, statistic=None, unit=None)

How often this Lambda is throttled.

Sum over 5 minutes

Parameters:

Return type:

Metric

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

architecture

The architecture of this Lambda Function.

connections

Access the Connections object.

Will fail if not a VPC-enabled Lambda Function

edge_arn

The ARN of the version for Lambda@Edge.

env

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

function_arn

The ARN fo the function.

function_name

The name of the function.

grant_principal

The principal this Lambda Function is running as.

is_bound_to_vpc

Whether or not this Lambda function was bound to a VPC.

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

lambda_

The underlying AWS Lambda function.

latest_version

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

The construct tree node associated with this construct.

permissions_node

The construct node where permissions are attached.

resource_arns_for_grant_invoke

The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().

role

The IAM role associated with this function.

Undefined if the function was imported without a role.

stack

The stack in which this resource is defined.

version

The most recently deployed version of this function.

Static Methods

classmethod from_version_arn(scope, id, version_arn)

Construct a Version object from a Version ARN.

Parameters:

Return type:

IVersion

classmethod from_version_attributes(scope, id, *, lambda_, version)

Parameters:

Return type:

IVersion

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters:

x (Any)

Return type:

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters:

construct (IConstruct)

Return type:

bool