| Language | Type name |
.NET | Amazon.CDK.AWS.Lambda.Python.Alpha.PythonFunction |
Go | github.com/aws/aws-cdk-go/awscdklambdapythonalpha/v2#PythonFunction |
Java | software.amazon.awscdk.services.lambda.python.alpha.PythonFunction |
Python | aws_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
| Name | Type | Description |
| entry๐น | string | Path to the source of the function or the location for dependencies. |
| runtime๐น | Runtime | The runtime environment. |
| adot Instrumentation?๐น | Adot Instrumentation Config | Specify the configuration of AWS Distro for OpenTelemetry (ADOT) instrumentation. |
| allow All Ipv6 Outbound?๐น | boolean | Whether to allow the Lambda to send all ipv6 network traffic. |
| allow All Outbound?๐น | boolean | Whether to allow the Lambda to send all network traffic (except ipv6). |
| allow Public Subnet?๐น | boolean | Lambda Functions in a public subnet can NOT access the internet. |
| application Log Level?โ ๏ธ | string | Sets the application log level for the function. |
| application Log Level V2?๐น | Application Log Level | Sets the application log level for the function. |
| architecture?๐น | Architecture | The system architectures compatible with this lambda function. |
| bundling?๐น | Bundling Options | Bundling options to use for this function. |
| code Signing Config?๐น | ICode Signing Config Ref | Code signing config associated with this function. |
| current Version Options?๐น | Version Options | Options for the lambda.Version resource automatically created by the fn.currentVersion method. |
| dead Letter Queue?๐น | IQueue | The SQS queue to use if DLQ is enabled. |
| dead Letter Queue Enabled?๐น | boolean | Enabled DLQ. |
| dead Letter Topic?๐น | ITopic | The SNS topic to use as a DLQ. |
| description?๐น | string | A description of the function. |
| durable Config?๐น | Durable Config | The durable configuration for the function. |
| environment?๐น | { [string]: string } | Key-value pairs that Lambda caches and makes available for your Lambda functions. |
| environment Encryption?๐น | IKey Ref | The AWS KMS key that's used to encrypt your function's environment variables. |
| ephemeral Storage Size?๐น | Size | The size of the functionโs /tmp directory in MiB. |
| events?๐น | IEvent Source[] | Event sources for this function. |
| filesystem?๐น | File System | The filesystem configuration for the lambda function. |
| function Name?๐น | string | A name for the function. |
| handler?๐น | string | The name of the exported handler in the index file. |
| index?๐น | string | The 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 Version | Specify the version of CloudWatch Lambda insights to use for monitoring. |
| ipv6 Allowed For Dual Stack?๐น | boolean | Allows 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?โ ๏ธ | string | Sets the logFormat for the function. |
| log Group?๐น | ILog Group Ref | The log group the function sends logs to. |
| log Removal Policy?โ ๏ธ | Removal Policy | Determine the removal policy of the log group that is auto-created by this construct. |
| log Retention?โ ๏ธ | Retention Days | The number of days log events are kept in CloudWatch Logs. |
| log Retention Retry Options?๐น | Log Retention Retry Options | When log retention is specified, a custom resource attempts to create the CloudWatch log group. |
| log Retention Role?๐น | IRole | The IAM role for the Lambda function associated with the custom resource that sets the retention policy. |
| logging Format?๐น | Logging Format | Sets the loggingFormat for the function. |
| max Event Age?๐น | Duration | The maximum age of a request that Lambda sends to a function for processing. |
| memory Size?๐น | number | The amount of memory, in MB, that is allocated to your Lambda function. |
| on Failure?๐น | IDestination | The destination for failed invocations. |
| on Success?๐น | IDestination | The destination for successful invocations. |
| params And Secrets?๐น | Params And Secrets Layer Version | Specify the configuration of Parameters and Secrets Extension. |
| profiling?๐น | boolean | Enable profiling. |
| profiling Group?๐น | IProfiling Group | Profiling Group. |
| recursive Loop?๐น | Recursive Loop | Sets the Recursive Loop Protection for Lambda Function. |
| reserved Concurrent Executions?๐น | number | The maximum of concurrent executions you want to reserve for the function. |
| retry Attempts?๐น | number | The maximum number of times to retry when the function returns an error. |
| role?๐น | IRole | Lambda execution role. |
| runtime Management Mode?๐น | Runtime Management Mode | Sets 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 Conf | Enable SnapStart for Lambda Function. |
| system Log Level?โ ๏ธ | string | Sets the system log level for the function. |
| system Log Level V2?๐น | System Log Level | Sets the system log level for the function. |
| tenancy Config?๐น | Tenancy Config | The tenancy configuration for the function. |
| timeout?๐น | Duration | The function execution time (in seconds) after which Lambda terminates the function. |
| tracing?๐น | Tracing | Enable AWS X-Ray Tracing for Lambda Function. |
| vpc?๐น | IVpc | VPC network to place Lambda network interfaces. |
| vpc Subnets?๐น | Subnet Selection | Where 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
| Name | Type | Description |
| architecture๐น | Architecture | The architecture of this Lambda Function (this is an optional attribute and defaults to X86_64). |
| connections๐น | Connections | Access the Connections object. |
| current Version๐น | 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. |
| env๐น | Resource Environment | The environment this resource belongs to. |
| function Arn๐น | string | ARN of this function. |
| function Name๐น | string | Name of this function. |
| function Ref๐น | Function Reference | A reference to a Function resource. |
| grant Principal๐น | IPrincipal | The principal this Lambda Function is running as. |
| is Bound To Vpc๐น | boolean | Whether or not this Lambda function was bound to a VPC. |
| latest Version๐น | IVersion | The $LATEST version of this function. |
| log Group๐น | ILog Group | The LogGroup where the Lambda function's logs are made available. |
| node๐น | Node | The tree node. |
| permissions Node๐น | Node | The 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๐น | Runtime | The runtime configured for this lambda. |
| stack๐น | Stack | The stack in which this resource is defined. |
| dead Letter Queue?๐น | IQueue | The DLQ (as queue) associated with this Lambda Function (this is an optional attribute). |
| dead Letter Topic?๐น | ITopic | The DLQ (as topic) associated with this Lambda Function (this is an optional attribute). |
| role?๐น | IRole | Execution role associated with this function. |
| tenancy Config?๐น | Tenancy Config | The tenancy configuration for this function. |
| timeout?๐น | Duration | The timeout configured for this lambda. |
| static PROPERTY_INJECTION_ID๐น | string | Uniquely 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
| Name | Description |
| 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
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
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.