docs.aws.amazon.com

LanguageType name
.NETAmazon.CDK.AWS.Lambda.Python.Alpha.PythonFunction
Gogithub.com/aws/aws-cdk-go/awscdklambdapythonalpha/v2#PythonFunction
Javasoftware.amazon.awscdk.services.lambda.python.alpha.PythonFunction
Pythonaws_cdk.aws_lambda_python_alpha.PythonFunction
TypeScript (source)@aws-cdk/aws-lambda-python-alpha ยป PythonFunction

Implements IConstruct, IDependable, IResource, IEnvironment Aware, IFunction, IConnectable, IGrantable, IFunction Ref, IClient Vpn Connection Handler

A Python Lambda function.

Example

const entry = '/path/to/function';
const image = DockerImage.fromBuild(entry);
new python.PythonFunction(this, 'function', {
  entry,
  runtime: Runtime.PYTHON_3_8,
  bundling: {
    buildArgs: { PIP_INDEX_URL: "https://your.index.url/simple/", PIP_EXTRA_INDEX_URL: "https://your.extra-index.url/simple/" },
  },
});

Initializer

new PythonFunction(scope: Construct, id: string, props: PythonFunctionProps)

Parameters

Construct Props

NameTypeDescription
entry๐Ÿ”นstringPath to the source of the function or the location for dependencies.
runtime๐Ÿ”นRuntimeThe runtime environment.
adot Instrumentation?๐Ÿ”นAdot Instrumentation ConfigSpecify the configuration of AWS Distro for OpenTelemetry (ADOT) instrumentation.
allow All Ipv6 Outbound?๐Ÿ”นbooleanWhether to allow the Lambda to send all ipv6 network traffic.
allow All Outbound?๐Ÿ”นbooleanWhether to allow the Lambda to send all network traffic (except ipv6).
allow Public Subnet?๐Ÿ”นbooleanLambda Functions in a public subnet can NOT access the internet.
application Log Level?โš ๏ธstringSets the application log level for the function.
application Log Level V2?๐Ÿ”นApplication Log LevelSets the application log level for the function.
architecture?๐Ÿ”นArchitectureThe system architectures compatible with this lambda function.
bundling?๐Ÿ”นBundling OptionsBundling options to use for this function.
code Signing Config?๐Ÿ”นICode Signing Config RefCode signing config associated with this function.
current Version Options?๐Ÿ”นVersion OptionsOptions for the lambda.Version resource automatically created by the fn.currentVersion method.
dead Letter Queue?๐Ÿ”นIQueueThe SQS queue to use if DLQ is enabled.
dead Letter Queue Enabled?๐Ÿ”นbooleanEnabled DLQ.
dead Letter Topic?๐Ÿ”นITopicThe SNS topic to use as a DLQ.
description?๐Ÿ”นstringA description of the function.
durable Config?๐Ÿ”นDurable ConfigThe durable configuration for the function.
environment?๐Ÿ”น{ [string]: string }Key-value pairs that Lambda caches and makes available for your Lambda functions.
environment Encryption?๐Ÿ”นIKey RefThe AWS KMS key that's used to encrypt your function's environment variables.
ephemeral Storage Size?๐Ÿ”นSizeThe size of the functionโ€™s /tmp directory in MiB.
events?๐Ÿ”นIEvent Source[]Event sources for this function.
filesystem?๐Ÿ”นFile SystemThe filesystem configuration for the lambda function.
function Name?๐Ÿ”นstringA name for the function.
handler?๐Ÿ”นstringThe name of the exported handler in the index file.
index?๐Ÿ”นstringThe path (relative to entry) to the index file containing the exported handler.
initial Policy?๐Ÿ”นPolicy Statement[]Initial policy statements to add to the created Lambda Role.
insights Version?๐Ÿ”นLambda Insights VersionSpecify the version of CloudWatch Lambda insights to use for monitoring.
ipv6 Allowed For Dual Stack?๐Ÿ”นbooleanAllows outbound IPv6 traffic on VPC functions that are connected to dual-stack subnets.
layers?๐Ÿ”นILayer Version[]A list of layers to add to the function's execution environment.
log Format?โš ๏ธstringSets the logFormat for the function.
log Group?๐Ÿ”นILog Group RefThe log group the function sends logs to.
log Removal Policy?โš ๏ธRemoval PolicyDetermine the removal policy of the log group that is auto-created by this construct.
log Retention?โš ๏ธRetention DaysThe number of days log events are kept in CloudWatch Logs.
log Retention Retry Options?๐Ÿ”นLog Retention Retry OptionsWhen log retention is specified, a custom resource attempts to create the CloudWatch log group.
log Retention Role?๐Ÿ”นIRoleThe IAM role for the Lambda function associated with the custom resource that sets the retention policy.
logging Format?๐Ÿ”นLogging FormatSets the loggingFormat for the function.
max Event Age?๐Ÿ”นDurationThe maximum age of a request that Lambda sends to a function for processing.
memory Size?๐Ÿ”นnumberThe amount of memory, in MB, that is allocated to your Lambda function.
on Failure?๐Ÿ”นIDestinationThe destination for failed invocations.
on Success?๐Ÿ”นIDestinationThe destination for successful invocations.
params And Secrets?๐Ÿ”นParams And Secrets Layer VersionSpecify the configuration of Parameters and Secrets Extension.
profiling?๐Ÿ”นbooleanEnable profiling.
profiling Group?๐Ÿ”นIProfiling GroupProfiling Group.
recursive Loop?๐Ÿ”นRecursive LoopSets the Recursive Loop Protection for Lambda Function.
reserved Concurrent Executions?๐Ÿ”นnumberThe maximum of concurrent executions you want to reserve for the function.
retry Attempts?๐Ÿ”นnumberThe maximum number of times to retry when the function returns an error.
role?๐Ÿ”นIRoleLambda execution role.
runtime Management Mode?๐Ÿ”นRuntime Management ModeSets the runtime management configuration for a function's version.
security Groups?๐Ÿ”นISecurity Group[]The list of security groups to associate with the Lambda's network interfaces.
snap Start?๐Ÿ”นSnap Start ConfEnable SnapStart for Lambda Function.
system Log Level?โš ๏ธstringSets the system log level for the function.
system Log Level V2?๐Ÿ”นSystem Log LevelSets the system log level for the function.
tenancy Config?๐Ÿ”นTenancy ConfigThe tenancy configuration for the function.
timeout?๐Ÿ”นDurationThe function execution time (in seconds) after which Lambda terminates the function.
tracing?๐Ÿ”นTracingEnable AWS X-Ray Tracing for Lambda Function.
vpc?๐Ÿ”นIVpcVPC network to place Lambda network interfaces.
vpc Subnets?๐Ÿ”นSubnet SelectionWhere to place the network interfaces within the VPC.

entry๐Ÿ”น

Type: string

Path to the source of the function or the location for dependencies.


runtime๐Ÿ”น

Type: Runtime

The runtime environment.

Only runtimes of the Python family are supported.


adotInstrumentation?๐Ÿ”น

Type: Adot Instrumentation Config (optional, default: No ADOT instrumentation)

Specify the configuration of AWS Distro for OpenTelemetry (ADOT) instrumentation.

See also: https://aws-otel.github.io/docs/getting-started/lambda


allowAllIpv6Outbound?๐Ÿ”น

Type: boolean (optional, default: false)

Whether to allow the Lambda to send all ipv6 network traffic.

If set to true, there will only be a single egress rule which allows all outbound ipv6 traffic. If set to false, you must individually add traffic rules to allow the Lambda to connect to network targets using ipv6.

Do not specify this property if the securityGroups or securityGroup property is set. Instead, configure allowAllIpv6Outbound directly on the security group.


allowAllOutbound?๐Ÿ”น

Type: boolean (optional, default: true)

Whether to allow the Lambda to send all network traffic (except ipv6).

If set to false, you must individually add traffic rules to allow the Lambda to connect to network targets.

Do not specify this property if the securityGroups or securityGroup property is set. Instead, configure allowAllOutbound directly on the security group.


allowPublicSubnet?๐Ÿ”น

Type: boolean (optional, default: false)

Lambda Functions in a public subnet can NOT access the internet.

Use this property to acknowledge this limitation and still place the function in a public subnet.

See also: https://stackoverflow.com/questions/52992085/why-cant-an-aws-lambda-function-inside-a-public-subnet-in-a-vpc-connect-to-the/52994841#52994841


applicationLogLevel?โš ๏ธ

โš ๏ธ Deprecated: Use applicationLogLevelV2 as a property instead.

Type: string (optional, default: "INFO")

Sets the application log level for the function.


applicationLogLevelV2?๐Ÿ”น

Type: Application Log Level (optional, default: ApplicationLogLevel.INFO)

Sets the application log level for the function.


architecture?๐Ÿ”น

Type: Architecture (optional, default: Architecture.X86_64)

The system architectures compatible with this lambda function.


bundling?๐Ÿ”น

Type: Bundling Options (optional, default: Use the default bundling Docker image, with x86_64 architecture.)

Bundling options to use for this function.

Use this to specify custom bundling options like the bundling Docker image, asset hash type, custom hash, architecture, etc.


codeSigningConfig?๐Ÿ”น

Type: ICode Signing Config Ref (optional, default: Not Sign the Code)

Code signing config associated with this function.


currentVersionOptions?๐Ÿ”น

Type: Version Options (optional, default: default options as described in VersionOptions)

Options for the lambda.Version resource automatically created by the fn.currentVersion method.


deadLetterQueue?๐Ÿ”น

Type: IQueue (optional, default: SQS queue with 14 day retention period if deadLetterQueueEnabled is true)

The SQS queue to use if DLQ is enabled.

If SNS topic is desired, specify deadLetterTopic property instead.


deadLetterQueueEnabled?๐Ÿ”น

Type: boolean (optional, default: false unless deadLetterQueue is set, which implies DLQ is enabled.)

Enabled DLQ.

If deadLetterQueue is undefined, an SQS queue with default options will be defined for your Function.


deadLetterTopic?๐Ÿ”น

Type: ITopic (optional, default: no SNS topic)

The SNS topic to use as a DLQ.

Note that if deadLetterQueueEnabled is set to true, an SQS queue will be created rather than an SNS topic. Using an SNS topic as a DLQ requires this property to be set explicitly.


description?๐Ÿ”น

Type: string (optional, default: No description.)

A description of the function.


durableConfig?๐Ÿ”น

Type: Durable Config (optional, default: No durable configuration)

The durable configuration for the function.

If durability is added to an existing function, a resource replacement will be triggered. See the 'durableConfig' section in the module README for more details.


environment?๐Ÿ”น

Type: { [string]: string } (optional, default: No environment variables.)

Key-value pairs that Lambda caches and makes available for your Lambda functions.

Use environment variables to apply configuration changes, such as test and production environment configurations, without changing your Lambda function source code.


environmentEncryption?๐Ÿ”น

Type: IKey Ref (optional, default: AWS Lambda creates and uses an AWS managed customer master key (CMK).)

The AWS KMS key that's used to encrypt your function's environment variables.


ephemeralStorageSize?๐Ÿ”น

Type: Size (optional, default: 512 MiB)

The size of the functionโ€™s /tmp directory in MiB.


events?๐Ÿ”น

Type: IEvent Source[] (optional, default: No event sources.)

Event sources for this function.

You can also add event sources using addEventSource.


filesystem?๐Ÿ”น

Type: File System (optional, default: will not mount any filesystem)

The filesystem configuration for the lambda function.


functionName?๐Ÿ”น

Type: string (optional, default: AWS CloudFormation generates a unique physical ID and uses that ID for the function's name. For more information, see Name Type.)

A name for the function.


handler?๐Ÿ”น

Type: string (optional, default: handler)

The name of the exported handler in the index file.


index?๐Ÿ”น

Type: string (optional, default: index.py)

The path (relative to entry) to the index file containing the exported handler.


initialPolicy?๐Ÿ”น

Type: Policy Statement[] (optional, default: No policy statements are added to the created Lambda role.)

Initial policy statements to add to the created Lambda Role.

You can call addToRolePolicy to the created lambda to add statements post creation.


insightsVersion?๐Ÿ”น

Type: Lambda Insights Version (optional, default: No Lambda Insights)

Specify the version of CloudWatch Lambda insights to use for monitoring.

See also: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Lambda-Insights-Getting-Started-docker.html


ipv6AllowedForDualStack?๐Ÿ”น

Type: boolean (optional, default: false)

Allows outbound IPv6 traffic on VPC functions that are connected to dual-stack subnets.

Only used if 'vpc' is supplied.


layers?๐Ÿ”น

Type: ILayer Version[] (optional, default: No layers.)

A list of layers to add to the function's execution environment.

You can configure your Lambda function to pull in additional code during initialization in the form of layers. Layers are packages of libraries or other dependencies that can be used by multiple functions.


logFormat?โš ๏ธ

โš ๏ธ Deprecated: Use loggingFormat as a property instead.

Type: string (optional, default: "Text")

Sets the logFormat for the function.


logGroup?๐Ÿ”น

Type: ILog Group Ref (optional, default: /aws/lambda/${this.functionName} - default log group created by Lambda)

The log group the function sends logs to.

By default, Lambda functions send logs to an automatically created default log group named /aws/lambda/<function name>. However you cannot change the properties of this auto-created log group using the AWS CDK, e.g. you cannot set a different log retention.

Use the logGroup property to create a fully customizable LogGroup ahead of time, and instruct the Lambda function to send logs to it.

Providing a user-controlled log group was rolled out to commercial regions on 2023-11-16. If you are deploying to another type of region, please check regional availability first.


logRemovalPolicy?โš ๏ธ

โš ๏ธ Deprecated: use logGroup instead

Type: Removal Policy (optional, default: RemovalPolicy.Retain)

Determine the removal policy of the log group that is auto-created by this construct.

Normally you want to retain the log group so you can diagnose issues from logs even after a deployment that no longer includes the log group. In that case, use the normal date-based retention policy to age out your logs.


logRetention?โš ๏ธ

โš ๏ธ Deprecated: use logGroup instead

Type: Retention Days (optional, default: logs.RetentionDays.INFINITE)

The number of days log events are kept in CloudWatch Logs.

When updating this property, unsetting it doesn't remove the log retention policy. To remove the retention policy, set the value to INFINITE.

This is a legacy API and we strongly recommend you move away from it if you can. Instead create a fully customizable log group with logs.LogGroup and use the logGroup property to instruct the Lambda function to send logs to it. Migrating from logRetention to logGroup will cause the name of the log group to change. Users and code and referencing the name verbatim will have to adjust.

In AWS CDK code, you can access the log group name directly from the LogGroup construct:

import * as logs from 'aws-cdk-lib/aws-logs';
declare const myLogGroup: logs.LogGroup;
myLogGroup.logGroupName;

logRetentionRetryOptions?๐Ÿ”น

Type: Log Retention Retry Options (optional, default: Default AWS SDK retry options.)

When log retention is specified, a custom resource attempts to create the CloudWatch log group.

These options control the retry policy when interacting with CloudWatch APIs.

This is a legacy API and we strongly recommend you migrate to logGroup if you can. logGroup allows you to create a fully customizable log group and instruct the Lambda function to send logs to it.


logRetentionRole?๐Ÿ”น

Type: IRole (optional, default: A new role is created.)

The IAM role for the Lambda function associated with the custom resource that sets the retention policy.

This is a legacy API and we strongly recommend you migrate to logGroup if you can. logGroup allows you to create a fully customizable log group and instruct the Lambda function to send logs to it.


loggingFormat?๐Ÿ”น

Type: Logging Format (optional, default: LoggingFormat.TEXT)

Sets the loggingFormat for the function.


maxEventAge?๐Ÿ”น

Type: Duration (optional, default: Duration.hours(6))

The maximum age of a request that Lambda sends to a function for processing.

Minimum: 60 seconds Maximum: 6 hours


memorySize?๐Ÿ”น

Type: number (optional, default: 128)

The amount of memory, in MB, that is allocated to your Lambda function.

Lambda uses this value to proportionally allocate the amount of CPU power. For more information, see Resource Model in the AWS Lambda Developer Guide.


onFailure?๐Ÿ”น

Type: IDestination (optional, default: no destination)

The destination for failed invocations.


onSuccess?๐Ÿ”น

Type: IDestination (optional, default: no destination)

The destination for successful invocations.


paramsAndSecrets?๐Ÿ”น

Type: Params And Secrets Layer Version (optional, default: No Parameters and Secrets Extension)

Specify the configuration of Parameters and Secrets Extension.

See also: https://docs.aws.amazon.com/systems-manager/latest/userguide/ps-integration-lambda-extensions.html


profiling?๐Ÿ”น

Type: boolean (optional, default: No profiling.)

Enable profiling.

See also: https://docs.aws.amazon.com/codeguru/latest/profiler-ug/setting-up-lambda.html


profilingGroup?๐Ÿ”น

Type: IProfiling Group (optional, default: A new profiling group will be created if profiling is set.)

Profiling Group.

See also: https://docs.aws.amazon.com/codeguru/latest/profiler-ug/setting-up-lambda.html


recursiveLoop?๐Ÿ”น

Type: Recursive Loop (optional, default: RecursiveLoop.Terminate)

Sets the Recursive Loop Protection for Lambda Function.

It lets Lambda detect and terminate unintended recursive loops.


reservedConcurrentExecutions?๐Ÿ”น

Type: number (optional, default: No specific limit - account limit.)

The maximum of concurrent executions you want to reserve for the function.

See also: https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html


retryAttempts?๐Ÿ”น

Type: number (optional, default: 2)

The maximum number of times to retry when the function returns an error.

Minimum: 0 Maximum: 2


role?๐Ÿ”น

Type: IRole (optional, default: A unique role will be generated for this lambda function. Both supplied and generated roles can always be changed by calling addToRolePolicy.)

Lambda execution role.

This is the role that will be assumed by the function upon execution. It controls the permissions that the function will have. The Role must be assumable by the 'lambda.amazonaws.com' service principal.

The default Role automatically has permissions granted for Lambda execution. If you provide a Role, you must add the relevant AWS managed policies yourself.

The relevant managed policies are "service-role/AWSLambdaBasicExecutionRole" and "service-role/AWSLambdaVPCAccessExecutionRole".


runtimeManagementMode?๐Ÿ”น

Type: Runtime Management Mode (optional, default: Auto)

Sets the runtime management configuration for a function's version.


securityGroups?๐Ÿ”น

Type: ISecurity Group[] (optional, default: If the function is placed within a VPC and a security group is not specified, either by this or securityGroup prop, a dedicated security group will be created for this function.)

The list of security groups to associate with the Lambda's network interfaces.

Only used if 'vpc' is supplied.


snapStart?๐Ÿ”น

Type: Snap Start Conf (optional, default: No snapstart)

Enable SnapStart for Lambda Function.

SnapStart is currently supported for Java 11, Java 17, Python 3.12, Python 3.13, and .NET 8 runtime


systemLogLevel?โš ๏ธ

โš ๏ธ Deprecated: Use systemLogLevelV2 as a property instead.

Type: string (optional, default: "INFO")

Sets the system log level for the function.


systemLogLevelV2?๐Ÿ”น

Type: System Log Level (optional, default: SystemLogLevel.INFO)

Sets the system log level for the function.


tenancyConfig?๐Ÿ”น

Type: Tenancy Config (optional, default: Tenant isolation is not enabled)

The tenancy configuration for the function.


timeout?๐Ÿ”น

Type: Duration (optional, default: Duration.seconds(3))

The function execution time (in seconds) after which Lambda terminates the function.

Because the execution time affects cost, set this value based on the function's expected execution time.


tracing?๐Ÿ”น

Type: Tracing (optional, default: Tracing.Disabled)

Enable AWS X-Ray Tracing for Lambda Function.


vpc?๐Ÿ”น

Type: IVpc (optional, default: Function is not placed within a VPC.)

VPC network to place Lambda network interfaces.

Specify this if the Lambda function needs to access resources in a VPC. This is required when vpcSubnets is specified.


vpcSubnets?๐Ÿ”น

Type: Subnet Selection (optional, default: the Vpc default strategy if not specified)

Where to place the network interfaces within the VPC.

This requires vpc to be specified in order for interfaces to actually be placed in the subnets. If vpc is not specify, this will raise an error.

Note: Internet access for Lambda Functions requires a NAT Gateway, so picking public subnets is not allowed (unless allowPublicSubnet is set to true).

Properties

NameTypeDescription
architecture๐Ÿ”นArchitectureThe architecture of this Lambda Function (this is an optional attribute and defaults to X86_64).
connections๐Ÿ”นConnectionsAccess the Connections object.
current Version๐Ÿ”นVersionReturns 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.
env๐Ÿ”นResource EnvironmentThe environment this resource belongs to.
function Arn๐Ÿ”นstringARN of this function.
function Name๐Ÿ”นstringName of this function.
function Ref๐Ÿ”นFunction ReferenceA reference to a Function resource.
grant Principal๐Ÿ”นIPrincipalThe principal this Lambda Function is running as.
is Bound To Vpc๐Ÿ”นbooleanWhether or not this Lambda function was bound to a VPC.
latest Version๐Ÿ”นIVersionThe $LATEST version of this function.
log Group๐Ÿ”นILog GroupThe LogGroup where the Lambda function's logs are made available.
node๐Ÿ”นNodeThe tree node.
permissions Node๐Ÿ”นNodeThe construct node where permissions are attached.
resource Arns For Grant Invoke๐Ÿ”นstring[]The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().
runtime๐Ÿ”นRuntimeThe runtime configured for this lambda.
stack๐Ÿ”นStackThe stack in which this resource is defined.
dead Letter Queue?๐Ÿ”นIQueueThe DLQ (as queue) associated with this Lambda Function (this is an optional attribute).
dead Letter Topic?๐Ÿ”นITopicThe DLQ (as topic) associated with this Lambda Function (this is an optional attribute).
role?๐Ÿ”นIRoleExecution role associated with this function.
tenancy Config?๐Ÿ”นTenancy ConfigThe tenancy configuration for this function.
timeout?๐Ÿ”นDurationThe timeout configured for this lambda.
static PROPERTY_INJECTION_ID๐Ÿ”นstringUniquely identifies this class.

architecture๐Ÿ”น

Type: Architecture

The architecture of this Lambda Function (this is an optional attribute and defaults to X86_64).


connections๐Ÿ”น

Type: Connections

Access the Connections object.

Will fail if not a VPC-enabled Lambda Function


currentVersion๐Ÿ”น

Type: 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 currentVersionOptions prop when initializing the lambda.Function.


env๐Ÿ”น

Type: Resource Environment

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๐Ÿ”น

Type: string

ARN of this function.


functionName๐Ÿ”น

Type: string

Name of this function.


functionRef๐Ÿ”น

Type: Function Reference

A reference to a Function resource.


grantPrincipal๐Ÿ”น

Type: IPrincipal

The principal this Lambda Function is running as.


isBoundToVpc๐Ÿ”น

Type: boolean

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

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


latestVersion๐Ÿ”น

Type: IVersion

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.


logGroup๐Ÿ”น

Type: ILog 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๐Ÿ”น

Type: Node

The tree node.


permissionsNode๐Ÿ”น

Type: Node

The construct node where permissions are attached.


resourceArnsForGrantInvoke๐Ÿ”น

Type: string[]

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


runtime๐Ÿ”น

Type: Runtime

The runtime configured for this lambda.


stack๐Ÿ”น

Type: Stack

The stack in which this resource is defined.


deadLetterQueue?๐Ÿ”น

Type: IQueue (optional)

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


deadLetterTopic?๐Ÿ”น

Type: ITopic (optional)

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


role?๐Ÿ”น

Type: IRole (optional)

Execution role associated with this function.


tenancyConfig?๐Ÿ”น

Type: Tenancy Config (optional)

The tenancy configuration for this function.


timeout?๐Ÿ”น

Type: Duration (optional)

The timeout configured for this lambda.


static PROPERTY_INJECTION_ID๐Ÿ”น

Type: string

Uniquely identifies this class.

Methods

NameDescription
add Alias(aliasName, options?)๐Ÿ”นDefines an alias for this function.
add Environment(key, value, options?)๐Ÿ”นAdds an environment variable to this Lambda function.
add Event Source(source)๐Ÿ”นAdds an event source to this function.
add Event Source Mapping(id, options)๐Ÿ”นAdds an event source that maps to this AWS Lambda function.
add Function Url(options?)๐Ÿ”นAdds a url to this lambda function.
add Layers(...layers)๐Ÿ”นAdds one or more Lambda Layers to this Lambda function.
add Permission(id, permission)๐Ÿ”นAdds a permission to the Lambda resource policy.
add To Role Policy(statement)๐Ÿ”นAdds a statement to the IAM role assumed by the instance.
apply Cross Stack Reference Strength(strength)๐Ÿ”นOverride the cross-stack reference strength for this resource.
apply Removal Policy(policy)๐Ÿ”นApply the given removal policy to this resource.
configure Async Invoke(options)๐Ÿ”นConfigures options for asynchronous invocation.
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.
grant Invoke(grantee)๐Ÿ”นGrant the given identity permissions to invoke this Lambda.
grant Invoke Composite Principal(compositePrincipal)๐Ÿ”นGrant multiple principals the ability to invoke this Lambda via CompositePrincipal.
grant Invoke Latest Version(grantee)๐Ÿ”นGrant the given identity permissions to invoke the $LATEST version or unqualified version of this Lambda.
grant Invoke Url(grantee)๐Ÿ”นGrant the given identity permissions to invoke this Lambda Function URL.
grant Invoke Version(grantee, version)๐Ÿ”นGrant the given identity permissions to invoke the given version of this Lambda.
invalidate Version Based On(x)๐Ÿ”นMix additional information into the hash of the Version object.
metric(metricName, props?)๐Ÿ”นReturn the given named metric for this Function.
metric Duration(props?)๐Ÿ”นHow long execution of this Lambda takes.
metric Errors(props?)๐Ÿ”นHow many invocations of this Lambda fail.
metric Invocations(props?)๐Ÿ”นHow often this Lambda is invoked.
metric Throttles(props?)๐Ÿ”นHow often this Lambda is throttled.
to String()๐Ÿ”นReturns a string representation of this construct.
with(...mixins)๐Ÿ”นApplies one or more mixins to this construct.

add Alias(aliasName, options?)๐Ÿ”น

public addAlias(aliasName: string, options?: AliasOptions): Alias

Parameters

  • aliasName string โ€” The name of the alias.
  • options Alias Options โ€” Alias options.

Returns

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.

declare const fn: lambda.Function;
fn.addAlias('Live');
// Is equivalent to
new lambda.Alias(this, 'AliasLive', {
  aliasName: 'Live',
  version: fn.currentVersion,
});

add Environment(key, value, options?)๐Ÿ”น

public addEnvironment(key: string, value: string, options?: EnvironmentOptions): Function

Parameters

  • key string โ€” The environment variable key.
  • value string โ€” The environment variable's value.
  • options Environment Options โ€” Environment variable options.

Returns

Adds an environment variable to this Lambda function.

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


add Event Source(source)๐Ÿ”น

public addEventSource(source: IEventSource): void

Parameters

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

add Event Source Mapping(id, options)๐Ÿ”น

public addEventSourceMapping(id: string, options: EventSourceMappingOptions): EventSourceMapping

Parameters

Returns

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


add Function Url(options?)๐Ÿ”น

public addFunctionUrl(options?: FunctionUrlOptions): FunctionUrl

Parameters

Returns

Adds a url to this lambda function.


add Layers(...layers)๐Ÿ”น

public addLayers(...layers: ILayerVersion[]): void

Parameters

Adds one or more Lambda Layers to this Lambda function.


add Permission(id, permission)๐Ÿ”น

public addPermission(id: string, permission: Permission): void

Parameters

  • id string โ€” The id for the permission construct.
  • permission Permission โ€” The permission to grant to this Lambda function.

Adds a permission to the Lambda resource policy.

See also: [Permission for details.](Permission for details.)


add To Role Policy(statement)๐Ÿ”น

public addToRolePolicy(statement: PolicyStatement): void

Parameters

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


apply Cross Stack Reference Strength(strength)๐Ÿ”น

public applyCrossStackReferenceStrength(strength: ReferenceStrength): void

Parameters

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.


apply Removal Policy(policy)๐Ÿ”น

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

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


configure Async Invoke(options)๐Ÿ”น

public configureAsyncInvoke(options: EventInvokeConfigOptions): void

Parameters

Configures options for asynchronous invocation.


consider Warning On Invoke Function Permissions(scope, action)๐Ÿ”น

public considerWarningOnInvokeFunctionPermissions(scope: Construct, action: string): void

Parameters

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.


grant Invoke(grantee)๐Ÿ”น

public grantInvoke(grantee: IGrantable): Grant

Parameters

Returns

Grant the given identity permissions to invoke this Lambda.

[disable-awslint:no-grants]


grant Invoke Composite Principal(compositePrincipal)๐Ÿ”น

public grantInvokeCompositePrincipal(compositePrincipal: CompositePrincipal): Grant[]

Parameters

Returns

Grant multiple principals the ability to invoke this Lambda via CompositePrincipal.

[disable-awslint:no-grants]


grant Invoke Latest Version(grantee)๐Ÿ”น

public grantInvokeLatestVersion(grantee: IGrantable): Grant

Parameters

Returns

Grant the given identity permissions to invoke the $LATEST version or unqualified version of this Lambda.

[disable-awslint:no-grants]


grant Invoke Url(grantee)๐Ÿ”น

public grantInvokeUrl(grantee: IGrantable): Grant

Parameters

Returns

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

[disable-awslint:no-grants]


grant Invoke Version(grantee, version)๐Ÿ”น

public grantInvokeVersion(grantee: IGrantable, version: IVersion): Grant

Parameters

Returns

Grant the given identity permissions to invoke the given version of this Lambda.

[disable-awslint:no-grants]


invalidate Version Based On(x)๐Ÿ”น

public invalidateVersionBasedOn(x: string): void

Parameters

  • x string

Mix additional information into the hash of the Version object.

The Lambda Function construct does its best to automatically create a new Version when anything about the Function changes (its code, its layers, any of the other properties).

However, you can sometimes source information from places that the CDK cannot look into, like the deploy-time values of SSM parameters. In those cases, the CDK would not force the creation of a new Version object when it actually should.

This method can be used to invalidate the current Version object. Pass in any string into this method, and make sure the string changes when you know a new Version needs to be created.

This method may be called more than once.


metric(metricName, props?)๐Ÿ”น

public metric(metricName: string, props?: MetricOptions): Metric

Parameters

Returns

Return the given named metric for this Function.


metric Duration(props?)๐Ÿ”น

public metricDuration(props?: MetricOptions): Metric

Parameters

Returns

How long execution of this Lambda takes.

Average over 5 minutes


metric Errors(props?)๐Ÿ”น

public metricErrors(props?: MetricOptions): Metric

Parameters

Returns

How many invocations of this Lambda fail.

Sum over 5 minutes


metric Invocations(props?)๐Ÿ”น

public metricInvocations(props?: MetricOptions): Metric

Parameters

Returns

How often this Lambda is invoked.

Sum over 5 minutes


metric Throttles(props?)๐Ÿ”น

public metricThrottles(props?: MetricOptions): Metric

Parameters

Returns

How often this Lambda is throttled.

Sum over 5 minutes


to String()๐Ÿ”น

public toString(): string

Returns

  • string

Returns a string representation of this construct.


with(...mixins)๐Ÿ”น

public with(...mixins: IMixin[]): IConstruct

Parameters

Returns

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.

Read the original on docs.aws.amazon.com โ†—