Class Function
- All Implemented Interfaces:
IConstruct
,IDependable
,IResource
,IClientVpnConnectionHandler
,IConnectable
,IGrantable
,IFunction
,software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
- Direct Known Subclasses:
DockerImageFunction
,GoFunction
,NodejsFunction
,PythonFunction
,TriggerFunction
The supplied file is subject to the 4096 bytes limit of being embedded in a CloudFormation template.
The construct includes an associated role with the lambda.
This construct does not yet reproduce all features from the underlying resource library.
Example:
import software.amazon.awscdk.services.signer.*; SigningProfile signingProfile = SigningProfile.Builder.create(this, "SigningProfile") .platform(Platform.AWS_LAMBDA_SHA384_ECDSA) .build(); CodeSigningConfig codeSigningConfig = CodeSigningConfig.Builder.create(this, "CodeSigningConfig") .signingProfiles(List.of(signingProfile)) .build(); Function.Builder.create(this, "Function") .codeSigningConfig(codeSigningConfig) .runtime(Runtime.NODEJS_16_X) .handler("index.handler") .code(Code.fromAsset(join(__dirname, "lambda-handler"))) .build();
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.ec2.IClientVpnConnectionHandler
IClientVpnConnectionHandler.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.core.IConstruct
IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.lambda.IFunction
IFunction.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.core.IResource
IResource.Jsii$Default
-
Constructor Summary
ModifierConstructorDescriptionprotected
Function
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
Function
(software.amazon.jsii.JsiiObjectRef objRef) Function
(software.constructs.Construct scope, String id, FunctionProps props) -
Method Summary
Modifier and TypeMethodDescriptionDefines an alias for this function.addAlias
(String aliasName, AliasOptions options) Defines an alias for this function.addEnvironment
(String key, String value) Adds an environment variable to this Lambda function.addEnvironment
(String key, String value, EnvironmentOptions options) Adds an environment variable to this Lambda function.void
addLayers
(@NotNull ILayerVersion... layers) Adds one or more Lambda Layers to this Lambda function.addVersion
(String name) 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.addVersion
(String name, String codeSha256) 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.addVersion
(String name, String codeSha256, String description) 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.addVersion
(String name, String codeSha256, String description, Number provisionedExecutions) 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.addVersion
(String name, String codeSha256, String description, Number provisionedExecutions, EventInvokeConfigOptions asyncInvokeConfig) 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.static void
classifyVersionProperty
(String propertyName, Boolean locked) Record whether specific properties in theAWS::Lambda::Function
resource should also be associated to the Version resource.static IFunction
fromFunctionArn
(software.constructs.Construct scope, String id, String functionArn) Import a lambda function into the CDK using its ARN.static IFunction
fromFunctionAttributes
(software.constructs.Construct scope, String id, FunctionAttributes attrs) Creates a Lambda function object which represents a function not defined within this stack.static IFunction
fromFunctionName
(software.constructs.Construct scope, String id, String functionName) Import a lambda function into the CDK using its name.The architecture of this Lambda Function (this is an optional attribute and defaults to X86_64).protected Boolean
Whether the addPermission() call adds any permissions.Returns alambda.Version
which represents the current version of this Lambda function.The DLQ (as queue) associated with this Lambda Function (this is an optional attribute).The DLQ (as topic) associated with this Lambda Function (this is an optional attribute).ARN of this function.Name of this function.The principal this Lambda Function is running as.The LogGroup where the Lambda function's logs are made available.The construct node where permissions are attached.The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().getRole()
Execution role associated with this function.The runtime configured for this lambda.The timeout configured for this lambda.static Metric
Return the given named metric for this Lambda.static Metric
metricAll
(String metricName, MetricOptions props) Return the given named metric for this Lambda.static Metric
Metric for the number of concurrent executions across all Lambdas.static Metric
Metric for the number of concurrent executions across all Lambdas.static Metric
Metric for the Duration executing all Lambdas.static Metric
metricAllDuration
(MetricOptions props) Metric for the Duration executing all Lambdas.static Metric
Metric for the number of Errors executing all Lambdas.static Metric
metricAllErrors
(MetricOptions props) Metric for the number of Errors executing all Lambdas.static Metric
Metric for the number of invocations of all Lambdas.static Metric
Metric for the number of invocations of all Lambdas.static Metric
Metric for the number of throttled invocations of all Lambdas.static Metric
metricAllThrottles
(MetricOptions props) Metric for the number of throttled invocations of all Lambdas.static Metric
Metric for the number of unreserved concurrent executions across all Lambdas.static Metric
Metric for the number of unreserved concurrent executions across all Lambdas.Methods inherited from class software.amazon.awscdk.services.lambda.FunctionBase
addEventSource, addEventSourceMapping, addFunctionUrl, addFunctionUrl, addPermission, addToRolePolicy, configureAsyncInvoke, considerWarningOnInvokeFunctionPermissions, getConnections, getIsBoundToVpc, getLatestVersion, grantInvoke, grantInvokeUrl, metric, metric, metricDuration, metricDuration, metricErrors, metricErrors, metricInvocations, metricInvocations, metricThrottles, metricThrottles, warnInvokeFunctionPermissions
Methods inherited from class software.amazon.awscdk.core.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isResource
Methods inherited from class software.amazon.awscdk.core.Construct
getNode, isConstruct, onPrepare, onSynthesize, onValidate, prepare, synthesize, validate
Methods inherited from class software.constructs.Construct
toString
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.amazon.awscdk.core.IConstruct
getNode
Methods inherited from interface software.amazon.awscdk.core.IResource
applyRemovalPolicy, getEnv, getStack
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
Function
protected Function(software.amazon.jsii.JsiiObjectRef objRef) -
Function
protected Function(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
Function
@Stability(Stable) public Function(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull FunctionProps props) - Parameters:
scope
- This parameter is required.id
- This parameter is required.props
- This parameter is required.
-
-
Method Details
-
classifyVersionProperty
@Stability(Stable) public static void classifyVersionProperty(@NotNull String propertyName, @NotNull Boolean locked) Record whether specific properties in theAWS::Lambda::Function
resource should also be associated to the Version resource.See 'currentVersion' section in the module README for more details.
- Parameters:
propertyName
- The property to classify. This parameter is required.locked
- whether the property should be associated to the version or not. This parameter is required.
-
fromFunctionArn
@Stability(Stable) @NotNull public static IFunction fromFunctionArn(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String functionArn) Import a lambda function into the CDK using its ARN.- Parameters:
scope
- This parameter is required.id
- This parameter is required.functionArn
- This parameter is required.
-
fromFunctionAttributes
@Stability(Stable) @NotNull public static IFunction fromFunctionAttributes(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull FunctionAttributes attrs) Creates a Lambda function object which represents a function not defined within this stack.- Parameters:
scope
- The parent construct. This parameter is required.id
- The name of the lambda construct. This parameter is required.attrs
- the attributes of the function to import. This parameter is required.
-
fromFunctionName
@Stability(Stable) @NotNull public static IFunction fromFunctionName(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String functionName) Import a lambda function into the CDK using its name.- Parameters:
scope
- This parameter is required.id
- This parameter is required.functionName
- This parameter is required.
-
metricAll
@Stability(Stable) @NotNull public static Metric metricAll(@NotNull String metricName, @Nullable MetricOptions props) Return the given named metric for this Lambda.- Parameters:
metricName
- This parameter is required.props
-
-
metricAll
Return the given named metric for this Lambda.- Parameters:
metricName
- This parameter is required.
-
metricAllConcurrentExecutions
@Stability(Stable) @NotNull public static Metric metricAllConcurrentExecutions(@Nullable MetricOptions props) Metric for the number of concurrent executions across all Lambdas.Default: max over 5 minutes
- Parameters:
props
-
-
metricAllConcurrentExecutions
Metric for the number of concurrent executions across all Lambdas.Default: max over 5 minutes
-
metricAllDuration
Metric for the Duration executing all Lambdas.Default: average over 5 minutes
- Parameters:
props
-
-
metricAllDuration
Metric for the Duration executing all Lambdas.Default: average over 5 minutes
-
metricAllErrors
Metric for the number of Errors executing all Lambdas.Default: sum over 5 minutes
- Parameters:
props
-
-
metricAllErrors
Metric for the number of Errors executing all Lambdas.Default: sum over 5 minutes
-
metricAllInvocations
@Stability(Stable) @NotNull public static Metric metricAllInvocations(@Nullable MetricOptions props) Metric for the number of invocations of all Lambdas.Default: sum over 5 minutes
- Parameters:
props
-
-
metricAllInvocations
Metric for the number of invocations of all Lambdas.Default: sum over 5 minutes
-
metricAllThrottles
Metric for the number of throttled invocations of all Lambdas.Default: sum over 5 minutes
- Parameters:
props
-
-
metricAllThrottles
Metric for the number of throttled invocations of all Lambdas.Default: sum over 5 minutes
-
metricAllUnreservedConcurrentExecutions
@Stability(Stable) @NotNull public static Metric metricAllUnreservedConcurrentExecutions(@Nullable MetricOptions props) Metric for the number of unreserved concurrent executions across all Lambdas.Default: max over 5 minutes
- Parameters:
props
-
-
metricAllUnreservedConcurrentExecutions
Metric for the number of unreserved concurrent executions across all Lambdas.Default: max over 5 minutes
-
addAlias
@Stability(Stable) @NotNull public Alias addAlias(@NotNull String aliasName, @Nullable AliasOptions options) 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.
Function fn; fn.addAlias("Live"); // Is equivalent to // Is equivalent to Alias.Builder.create(this, "AliasLive") .aliasName("Live") .version(fn.getCurrentVersion()) .build();
- Parameters:
aliasName
- The name of the alias. This parameter is required.options
- Alias options.
-
addAlias
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.
Function fn; fn.addAlias("Live"); // Is equivalent to // Is equivalent to Alias.Builder.create(this, "AliasLive") .aliasName("Live") .version(fn.getCurrentVersion()) .build();
- Parameters:
aliasName
- The name of the alias. This parameter is required.
-
addEnvironment
@Stability(Stable) @NotNull public Function addEnvironment(@NotNull String key, @NotNull String value, @Nullable EnvironmentOptions options) 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:
key
- The environment variable key. This parameter is required.value
- The environment variable's value. This parameter is required.options
- Environment variable options.
-
addEnvironment
@Stability(Stable) @NotNull public Function addEnvironment(@NotNull String key, @NotNull String value) 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:
key
- The environment variable key. This parameter is required.value
- The environment variable's value. This parameter is required.
-
addLayers
Adds one or more Lambda Layers to this Lambda function.- Parameters:
layers
- the layers to be added. This parameter is required.
-
addVersion
@Stability(Deprecated) @Deprecated @NotNull public Version addVersion(@NotNull String name, @Nullable String codeSha256, @Nullable String description, @Nullable Number provisionedExecutions, @Nullable EventInvokeConfigOptions asyncInvokeConfig) 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.(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:
name
- A unique name for this version. This parameter is required.codeSha256
- The SHA-256 hash of the most recently deployed Lambda source code, or omit to skip validation.description
- A description for this version.provisionedExecutions
- A provisioned concurrency configuration for a function's version.asyncInvokeConfig
- configuration for this version when it is invoked asynchronously.- Returns:
- A new Version object.
-
addVersion
@Stability(Deprecated) @Deprecated @NotNull public Version addVersion(@NotNull String name, @Nullable String codeSha256, @Nullable String description, @Nullable Number provisionedExecutions) 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.(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:
name
- A unique name for this version. This parameter is required.codeSha256
- The SHA-256 hash of the most recently deployed Lambda source code, or omit to skip validation.description
- A description for this version.provisionedExecutions
- A provisioned concurrency configuration for a function's version.- Returns:
- A new Version object.
-
addVersion
@Stability(Deprecated) @Deprecated @NotNull public Version addVersion(@NotNull String name, @Nullable String codeSha256, @Nullable String description) 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.(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:
name
- A unique name for this version. This parameter is required.codeSha256
- The SHA-256 hash of the most recently deployed Lambda source code, or omit to skip validation.description
- A description for this version.- Returns:
- A new Version object.
-
addVersion
@Stability(Deprecated) @Deprecated @NotNull public Version addVersion(@NotNull String name, @Nullable String codeSha256) 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.(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:
name
- A unique name for this version. This parameter is required.codeSha256
- The SHA-256 hash of the most recently deployed Lambda source code, or omit to skip validation.- Returns:
- A new Version object.
-
addVersion
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.(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:
name
- A unique name for this version. This parameter is required.- Returns:
- A new Version object.
-
getArchitecture
The architecture of this Lambda Function (this is an optional attribute and defaults to X86_64).- Specified by:
getArchitecture
in interfaceIFunction
- Specified by:
getArchitecture
in classFunctionBase
-
getCanCreatePermissions
Whether the addPermission() call adds any permissions.True for new Lambdas, false for version $LATEST and imported Lambdas from different accounts.
- Specified by:
getCanCreatePermissions
in classFunctionBase
-
getCurrentVersion
Returns alambda.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 thelambda.Function
. -
getFunctionArn
ARN of this function.- Specified by:
getFunctionArn
in interfaceIClientVpnConnectionHandler
- Specified by:
getFunctionArn
in interfaceIFunction
- Specified by:
getFunctionArn
in classFunctionBase
-
getFunctionName
Name of this function.- Specified by:
getFunctionName
in interfaceIClientVpnConnectionHandler
- Specified by:
getFunctionName
in interfaceIFunction
- Specified by:
getFunctionName
in classFunctionBase
-
getGrantPrincipal
The principal this Lambda Function is running as.- Specified by:
getGrantPrincipal
in interfaceIGrantable
- Specified by:
getGrantPrincipal
in classFunctionBase
-
getLogGroup
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. -
getPermissionsNode
The construct node where permissions are attached.- Specified by:
getPermissionsNode
in interfaceIFunction
- Specified by:
getPermissionsNode
in classFunctionBase
-
getResourceArnsForGrantInvoke
The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().- Specified by:
getResourceArnsForGrantInvoke
in interfaceIFunction
- Specified by:
getResourceArnsForGrantInvoke
in classFunctionBase
-
getRuntime
The runtime configured for this lambda. -
getDeadLetterQueue
The DLQ (as queue) associated with this Lambda Function (this is an optional attribute). -
getDeadLetterTopic
The DLQ (as topic) associated with this Lambda Function (this is an optional attribute). -
getRole
Execution role associated with this function.- Specified by:
getRole
in interfaceIFunction
- Specified by:
getRole
in classFunctionBase
-
getTimeout
The timeout configured for this lambda.
-