FunctionOptions Struct
Non runtime options.
Example
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_codeguruprofiler as codeguruprofiler } from 'aws-cdk-lib';
import { aws_ec2 as ec2 } from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';
import { aws_lambda as lambda } from 'aws-cdk-lib';
import { aws_logs as logs } from 'aws-cdk-lib';
import { aws_sns as sns } from 'aws-cdk-lib';
import { aws_sqs as sqs } from 'aws-cdk-lib';
import { aws_kms as interfaces_kms } from 'aws-cdk-lib/interfaces';
import { aws_lambda as interfaces_lambda } from 'aws-cdk-lib/interfaces';
import { aws_logs as interfaces_logs } from 'aws-cdk-lib/interfaces';
declare const adotLayerVersion: lambda.AdotLayerVersion;
declare const architecture: lambda.Architecture;
declare const codeSigningConfigRef: interfaces_lambda.ICodeSigningConfigRef;
declare const destination: lambda.IDestination;
declare const eventSource: lambda.IEventSource;
declare const fileSystem: lambda.FileSystem;
declare const keyRef: interfaces_kms.IKeyRef;
declare const lambdaInsightsVersion: lambda.LambdaInsightsVersion;
declare const layerVersion: lambda.LayerVersion;
declare const logGroupRef: interfaces_logs.ILogGroupRef;
declare const paramsAndSecretsLayerVersion: lambda.ParamsAndSecretsLayerVersion;
declare const policyStatement: iam.PolicyStatement;
declare const profilingGroup: codeguruprofiler.ProfilingGroup;
declare const queue: sqs.Queue;
declare const role: iam.Role;
declare const runtimeManagementMode: lambda.RuntimeManagementMode;
declare const securityGroup: ec2.SecurityGroup;
declare const size: cdk.Size;
declare const snapStartConf: lambda.SnapStartConf;
declare const subnet: ec2.Subnet;
declare const subnetFilter: ec2.SubnetFilter;
declare const tenancyConfig: lambda.TenancyConfig;
declare const topic: sns.Topic;
declare const vpc: ec2.Vpc;
const functionOptions: lambda.FunctionOptions = {
adotInstrumentation: {
execWrapper: lambda.AdotLambdaExecWrapper.REGULAR_HANDLER,
layerVersion: adotLayerVersion,
},
allowAllIpv6Outbound: false,
allowAllOutbound: false,
allowPublicSubnet: false,
applicationLogLevel: 'applicationLogLevel',
applicationLogLevelV2: lambda.ApplicationLogLevel.INFO,
architecture: architecture,
codeSigningConfig: codeSigningConfigRef,
currentVersionOptions: {
codeSha256: 'codeSha256',
description: 'description',
maxEventAge: cdk.Duration.minutes(30),
maxExecutionEnvironments: 123,
minExecutionEnvironments: 123,
onFailure: destination,
onSuccess: destination,
provisionedConcurrentExecutions: 123,
removalPolicy: cdk.RemovalPolicy.DESTROY,
retryAttempts: 123,
},
deadLetterQueue: queue,
deadLetterQueueEnabled: false,
deadLetterTopic: topic,
description: 'description',
durableConfig: {
executionTimeout: cdk.Duration.minutes(30),
// the properties below are optional
retentionPeriod: cdk.Duration.minutes(30),
},
environment: {
environmentKey: 'environment',
},
environmentEncryption: keyRef,
ephemeralStorageSize: size,
events: [eventSource],
filesystem: fileSystem,
functionName: 'functionName',
initialPolicy: [policyStatement],
insightsVersion: lambdaInsightsVersion,
ipv6AllowedForDualStack: false,
layers: [layerVersion],
logFormat: 'logFormat',
loggingFormat: lambda.LoggingFormat.TEXT,
logGroup: logGroupRef,
logRemovalPolicy: cdk.RemovalPolicy.DESTROY,
logRetention: logs.RetentionDays.ONE_DAY,
logRetentionRetryOptions: {
base: cdk.Duration.minutes(30),
maxRetries: 123,
},
logRetentionRole: role,
maxEventAge: cdk.Duration.minutes(30),
memorySize: 123,
onFailure: destination,
onSuccess: destination,
paramsAndSecrets: paramsAndSecretsLayerVersion,
profiling: false,
profilingGroup: profilingGroup,
recursiveLoop: lambda.RecursiveLoop.ALLOW,
reservedConcurrentExecutions: 123,
retryAttempts: 123,
role: role,
runtimeManagementMode: runtimeManagementMode,
securityGroups: [securityGroup],
snapStart: snapStartConf,
systemLogLevel: 'systemLogLevel',
systemLogLevelV2: lambda.SystemLogLevel.INFO,
tenancyConfig: tenancyConfig,
timeout: cdk.Duration.minutes(30),
tracing: lambda.Tracing.ACTIVE,
vpc: vpc,
vpcSubnets: {
availabilityZones: ['availabilityZones'],
onePerAz: false,
subnetFilters: [subnetFilter],
subnetGroupName: 'subnetGroupName',
subnets: [subnet],
subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
},
};
Properties
adotInstrumentationAdotInstrumentationConfigadot_instrumentationAdotInstrumentationConfigadotInstrumentationAdotInstrumentationConfigAdotInstrumentationAdotInstrumentationConfigAdotInstrumentationAdotInstrumentationConfig= No ADOT instrumentation#allowAllIpv6Outboundbooleanallow_all_ipv6_outboundboolallowAllIpv6OutboundBooleanAllowAllIpv6OutboundboolAllowAllIpv6Outbound*bool= false#notes
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.
allowAllOutboundbooleanallow_all_outboundboolallowAllOutboundBooleanAllowAllOutboundboolAllowAllOutbound*bool= true#notes
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.
allowPublicSubnetbooleanallow_public_subnetboolallowPublicSubnetBooleanAllowPublicSubnetboolAllowPublicSubnet*bool= false#Use this property to acknowledge this limitation and still place the function in a public subnet.
applicationLogLevelstringapplication_log_levelstrapplicationLogLevelStringApplicationLogLevelstringApplicationLogLevel*string= "INFO"deprecated#applicationLogLevelV2ApplicationLogLevelapplication_log_level_v2ApplicationLogLevelapplicationLogLevelV2ApplicationLogLevelApplicationLogLevelV2ApplicationLogLevelApplicationLogLevelV2ApplicationLogLevel= ApplicationLogLevel.INFO#architectureArchitecturearchitectureArchitecturearchitectureArchitectureArchitectureArchitectureArchitectureArchitecture= Architecture.X86_64#codeSigningConfigICodeSigningConfigRefcode_signing_configICodeSigningConfigRefcodeSigningConfigICodeSigningConfigRefCodeSigningConfigICodeSigningConfigRefCodeSigningConfigICodeSigningConfigRef= Not Sign the Code#currentVersionOptionsVersionOptionscurrent_version_optionsVersionOptionscurrentVersionOptionsVersionOptionsCurrentVersionOptionsVersionOptionsCurrentVersionOptionsVersionOptions= default options as described in …#default
Default: default options as described in VersionOptions
deadLetterQueueIQueuedead_letter_queueIQueuedeadLetterQueueIQueueDeadLetterQueueIQueueDeadLetterQueueIQueue= SQS queue with 14 day retention …#If SNS topic is desired, specify deadLetterTopic property instead.
default
Default: SQS queue with 14 day retention period if deadLetterQueueEnabled is true
deadLetterQueueEnabledbooleandead_letter_queue_enabledbooldeadLetterQueueEnabledBooleanDeadLetterQueueEnabledboolDeadLetterQueueEnabled*bool= false unless `deadLetterQueue` i…#If deadLetterQueue is undefined, an SQS queue with default options will be defined for your Function.
default
Default: false unless deadLetterQueue is set, which implies DLQ is enabled.
deadLetterTopicITopicdead_letter_topicITopicdeadLetterTopicITopicDeadLetterTopicITopicDeadLetterTopicITopic= no SNS topic#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.
descriptionstringdescriptionstrdescriptionStringDescriptionstringDescription*string= No description.#durableConfigDurableConfigdurable_configDurableConfigdurableConfigDurableConfigDurableConfigDurableConfigDurableConfigDurableConfig= No durable configuration#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{ [key: string]: string }environmenttyping.Mapping[str, str]environmentMap<String, String>EnvironmentIDictionary<string, string>Environment*map[string]*string= No environment variables.#Use environment variables to apply configuration changes, such as test and production environment configurations, without changing your Lambda function source code.
environmentEncryptionIKeyRefenvironment_encryptionIKeyRefenvironmentEncryptionIKeyRefEnvironmentEncryptionIKeyRefEnvironmentEncryptionIKeyRef= AWS Lambda creates and uses an A…#default
Default: AWS Lambda creates and uses an AWS managed customer master key (CMK).
ephemeralStorageSizeSizeephemeral_storage_sizeSizeephemeralStorageSizeSizeEphemeralStorageSizeSizeEphemeralStorageSizeSize= 512 MiB#eventsIEventSource[]eventstyping.List[IEventSource]eventsList<IEventSource>EventsIEventSource[]Events*[]IEventSource= No event sources.#You can also add event sources using addEventSource.
filesystemFileSystemfilesystemFileSystemfilesystemFileSystemFilesystemFileSystemFilesystemFileSystem= will not mount any filesystem#functionNamestringfunction_namestrfunctionNameStringFunctionNamestringFunctionName*string= AWS CloudFormation generates a u…#default
Default: AWS CloudFormation generates a unique physical ID and uses that ID for the function's name. For more information, see Name Type.
initialPolicyPolicyStatement[]initial_policytyping.List[PolicyStatement]initialPolicyList<PolicyStatement>InitialPolicyPolicyStatement[]InitialPolicy*[]PolicyStatement= No policy statements are added t…#You can call addToRolePolicy to the created lambda to add statements post creation.
default
Default: No policy statements are added to the created Lambda role.
insightsVersionLambdaInsightsVersioninsights_versionLambdaInsightsVersioninsightsVersionLambdaInsightsVersionInsightsVersionLambdaInsightsVersionInsightsVersionLambdaInsightsVersion= No Lambda Insights#ipv6AllowedForDualStackbooleanipv6_allowed_for_dual_stackboolipv6AllowedForDualStackBooleanIpv6AllowedForDualStackboolIpv6AllowedForDualStack*bool= false#Only used if 'vpc' is supplied.
layersILayerVersion[]layerstyping.List[ILayerVersion]layersList<ILayerVersion>LayersILayerVersion[]Layers*[]ILayerVersion= No layers.#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.
loggingFormatLoggingFormatlogging_formatLoggingFormatloggingFormatLoggingFormatLoggingFormatLoggingFormatLoggingFormatLoggingFormat= LoggingFormat.TEXT#logGroupILogGroupReflog_groupILogGroupReflogGroupILogGroupRefLogGroupILogGroupRefLogGroupILogGroupRef= `/aws/lambda/${this.functionName…#notes · default
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.
Default: /aws/lambda/${this.functionName} - default log group created by Lambda
logRemovalPolicyRemovalPolicylog_removal_policyRemovalPolicylogRemovalPolicyRemovalPolicyLogRemovalPolicyRemovalPolicyLogRemovalPolicyRemovalPolicy= RemovalPolicy.Retaindeprecated#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.
logRetentionRetentionDayslog_retentionRetentionDayslogRetentionRetentionDaysLogRetentionRetentionDaysLogRetentionRetentionDays= logs.RetentionDays.INFINITEdeprecated#notes
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;
logRetentionRetryOptionsLogRetentionRetryOptionslog_retention_retry_optionsLogRetentionRetryOptionslogRetentionRetryOptionsLogRetentionRetryOptionsLogRetentionRetryOptionsLogRetentionRetryOptionsLogRetentionRetryOptionsLogRetentionRetryOptions= Default AWS SDK retry options.#notes
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.
logRetentionRoleIRolelog_retention_roleIRolelogRetentionRoleIRoleLogRetentionRoleIRoleLogRetentionRoleIRole= A new role is created.#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.
maxEventAgeDurationmax_event_ageDurationmaxEventAgeDurationMaxEventAgeDurationMaxEventAgeDuration= Duration.hours(6)#Minimum: 60 seconds Maximum: 6 hours
Lambda uses this value to proportionally allocate the amount of CPU power. For more information, see Resource Model in the AWS Lambda Developer Guide.
onFailureIDestinationon_failureIDestinationonFailureIDestinationOnFailureIDestinationOnFailureIDestination= no destination#onSuccessIDestinationon_successIDestinationonSuccessIDestinationOnSuccessIDestinationOnSuccessIDestination= no destination#paramsAndSecretsParamsAndSecretsLayerVersionparams_and_secretsParamsAndSecretsLayerVersionparamsAndSecretsParamsAndSecretsLayerVersionParamsAndSecretsParamsAndSecretsLayerVersionParamsAndSecretsParamsAndSecretsLayerVersion= No Parameters and Secrets Extens…#default
Default: No Parameters and Secrets Extension
profilingGroupIProfilingGroupprofiling_groupIProfilingGroupprofilingGroupIProfilingGroupProfilingGroupIProfilingGroupProfilingGroupIProfilingGroup= A new profiling group will be cr…#default
Default: A new profiling group will be created if profiling is set.
recursiveLoopRecursiveLooprecursive_loopRecursiveLooprecursiveLoopRecursiveLoopRecursiveLoopRecursiveLoopRecursiveLoopRecursiveLoop= RecursiveLoop.Terminate#It lets Lambda detect and terminate unintended recursive loops.
reservedConcurrentExecutionsnumberreserved_concurrent_executionsint | floatreservedConcurrentExecutionsNumberReservedConcurrentExecutionsdoubleReservedConcurrentExecutions*float64= No specific limit - account limi…#default
Default: No specific limit - account limit.
retryAttemptsnumberretry_attemptsint | floatretryAttemptsNumberRetryAttemptsdoubleRetryAttempts*float64= 2#Minimum: 0 Maximum: 2
notes · default
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".
Default: A unique role will be generated for this lambda function. Both supplied and generated roles can always be changed by calling addToRolePolicy.
runtimeManagementModeRuntimeManagementModeruntime_management_modeRuntimeManagementModeruntimeManagementModeRuntimeManagementModeRuntimeManagementModeRuntimeManagementModeRuntimeManagementModeRuntimeManagementMode= Auto#securityGroupsISecurityGroup[]security_groupstyping.List[ISecurityGroup]securityGroupsList<ISecurityGroup>SecurityGroupsISecurityGroup[]SecurityGroups*[]ISecurityGroup= If the function is placed within…#Only used if 'vpc' is supplied.
default
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.
snapStartSnapStartConfsnap_startSnapStartConfsnapStartSnapStartConfSnapStartSnapStartConfSnapStartSnapStartConf= No snapstart#SnapStart is currently supported for Java 11, Java 17, Python 3.12, Python 3.13, and .NET 8 runtime, as well as container image (OCI) deployments.
systemLogLevelstringsystem_log_levelstrsystemLogLevelStringSystemLogLevelstringSystemLogLevel*string= "INFO"deprecated#systemLogLevelV2SystemLogLevelsystem_log_level_v2SystemLogLevelsystemLogLevelV2SystemLogLevelSystemLogLevelV2SystemLogLevelSystemLogLevelV2SystemLogLevel= SystemLogLevel.INFO#tenancyConfigTenancyConfigtenancy_configTenancyConfigtenancyConfigTenancyConfigTenancyConfigTenancyConfigTenancyConfigTenancyConfig= Tenant isolation is not enabled#Because the execution time affects cost, set this value based on the function's expected execution time.
Specify this if the Lambda function needs to access resources in a VPC. This is required when vpcSubnets is specified.
default
Default: Function is not placed within a VPC.
vpcSubnetsSubnetSelectionvpc_subnetsSubnetSelectionvpcSubnetsSubnetSelectionVpcSubnetsSubnetSelectionVpcSubnetsSubnetSelection= the Vpc default strategy if not …#notes · default
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).
Default: the Vpc default strategy if not specified