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

AWS Cloud Development Kit

class aws_cdk.aws_lambda.DockerImageFunction(scope, id, *, code, allow_all_outbound=None, allow_public_subnet=None, architecture=None, architectures=None, code_signing_config=None, current_version_options=None, dead_letter_queue=None, dead_letter_queue_enabled=None, dead_letter_topic=None, description=None, environment=None, environment_encryption=None, ephemeral_storage_size=None, events=None, filesystem=None, function_name=None, initial_policy=None, insights_version=None, layers=None, log_retention=None, log_retention_retry_options=None, log_retention_role=None, memory_size=None, profiling=None, profiling_group=None, reserved_concurrent_executions=None, role=None, security_group=None, security_groups=None, timeout=None, tracing=None, vpc=None, vpc_subnets=None, max_event_age=None, on_failure=None, on_success=None, retry_attempts=None)

Bases: Function

Create a lambda function where the handler is a docker image.

ExampleMetadata:

infused

Example:

lambda_.DockerImageFunction(self, "AssetFunction", code=lambda_.DockerImageCode.from_image_asset(path.join(__dirname, "docker-handler")) )

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)

Defines an alias for this function.

The alias will automatically be updated to point to the latest version of the function as it is being updated during a deployment:

fn: lambda.Function

fn.add_alias("Live")

Is equivalent to

lambda_.Alias(self, "AliasLive", alias_name="Live", version=fn.current_version )

Parameters:

Return type:

Alias

add_environment(key, value, *, remove_in_edge=None)

Adds an environment variable to this Lambda function.

If this is a ref to a Lambda function, this operation results in a no-op.

Parameters:

Return type:

Function

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_layers(*layers)

Adds one or more Lambda Layers to this Lambda function.

Parameters:

layers (ILayerVersion) – the layers to be added.

Throws:

if there are already 5 layers on this function, or the layer is incompatible with this function’s runtime.

Return type:

None

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

add_version(name, code_sha256=None, description=None, provisioned_executions=None, *, max_event_age=None, on_failure=None, on_success=None, retry_attempts=None)

(deprecated) Add a new version for this Lambda.

If you want to deploy through CloudFormation and use aliases, you need to add a new version (with a new name) to your Lambda every time you want to deploy an update. An alias can then refer to the newly created Version.

All versions should have distinct names, and you should not delete versions as long as your Alias needs to refer to them.

Parameters:

Return type:

Version

Returns:

A new Version object.

Deprecated:

This method will create an AWS::Lambda::Version resource which snapshots the AWS Lambda function at the time of its creation and it won’t get updated when the function changes. Instead, usethis.currentVersion to obtain a reference to a version resource that gets automatically recreated when the function configuration (or code) changes.

Stability:

deprecated

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 (this is an optional attribute and defaults to X86_64).

connections

Access the Connections object.

Will fail if not a VPC-enabled Lambda Function

current_version

Returns a lambda.Version which represents the current version of this Lambda function. A new version will be created every time the function’s configuration changes.

You can specify options for this version using the currentVersionOptionsprop when initializing the lambda.Function.

dead_letter_queue

The DLQ (as queue) associated with this Lambda Function (this is an optional attribute).

dead_letter_topic

The DLQ (as topic) associated with this Lambda Function (this is an optional attribute).

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

ARN of this function.

function_name

Name of this 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.

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.

log_group

The LogGroup where the Lambda function’s logs are made available.

If either logRetention is set or this property is called, a CloudFormation custom resource is added to the stack that pre-creates the log group as part of the stack deployment, if it already doesn’t exist, and sets the correct log retention period (never expire, by default).

Further, if the log group already exists and the logRetention is not set, the custom resource will reset the log retention to never expire even if it was configured with a different value.

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

Execution role associated with this function.

runtime

The runtime configured for this lambda.

stack

The stack in which this resource is defined.

timeout

The timeout configured for this lambda.

Static Methods

classmethod classify_version_property(property_name, locked)

Record whether specific properties in the AWS::Lambda::Function resource should also be associated to the Version resource.

See ‘currentVersion’ section in the module README for more details.

Parameters:

Return type:

None

classmethod from_function_arn(scope, id, function_arn)

Import a lambda function into the CDK using its ARN.

Parameters:

Return type:

IFunction

classmethod from_function_attributes(scope, id, *, function_arn, architecture=None, role=None, same_environment=None, security_group=None, security_group_id=None, skip_permissions=None)

Creates a Lambda function object which represents a function not defined within this stack.

Parameters:

Return type:

IFunction

classmethod from_function_name(scope, id, function_name)

Import a lambda function into the CDK using its name.

Parameters:

Return type:

IFunction

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

classmethod metric_all(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 Lambda.

Parameters:

Return type:

Metric

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

Metric for the number of concurrent executions across all Lambdas.

Parameters:

Default:

max over 5 minutes

Return type:

Metric

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

Metric for the Duration executing all Lambdas.

Parameters:

Default:

average over 5 minutes

Return type:

Metric

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

Metric for the number of Errors executing all Lambdas.

Parameters:

Default:

sum over 5 minutes

Return type:

Metric

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

Metric for the number of invocations of all Lambdas.

Parameters:

Default:

sum over 5 minutes

Return type:

Metric

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

Metric for the number of throttled invocations of all Lambdas.

Parameters:

Default:

sum over 5 minutes

Return type:

Metric

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

Metric for the number of unreserved concurrent executions across all Lambdas.

Parameters:

Default:

max over 5 minutes

Return type:

Metric