Class SingletonFunction
- All Implemented Interfaces:
IConstruct
,IDependable
,IResource
,IClientVpnConnectionHandler
,IConnectable
,IGrantable
,IFunction
,software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
This construct is a way to guarantee that the lambda function will be guaranteed to be part of the stack,
once and only once, irrespective of how many times the construct is declared to be part of the stack.
This is guaranteed as long as the uuid
property and the optional lambdaPurpose
property stay the same
whenever they're declared into the stack.
Example:
// The code below shows an example of how to instantiate this type. // The values are placeholders you should change. import software.amazon.awscdk.services.codeguruprofiler.*; import software.amazon.awscdk.services.ec2.*; import software.amazon.awscdk.services.iam.*; import software.amazon.awscdk.services.kms.*; import software.amazon.awscdk.services.lambda.*; import software.amazon.awscdk.services.logs.*; import software.amazon.awscdk.services.sns.*; import software.amazon.awscdk.services.sqs.*; import software.amazon.awscdk.core.*; Architecture architecture; Code code; CodeSigningConfig codeSigningConfig; IDestination destination; IEventSource eventSource; FileSystem fileSystem; Key key; LambdaInsightsVersion lambdaInsightsVersion; LayerVersion layerVersion; PolicyStatement policyStatement; ProfilingGroup profilingGroup; Queue queue; Role role; Runtime runtime; SecurityGroup securityGroup; Size size; Subnet subnet; SubnetFilter subnetFilter; Topic topic; Vpc vpc; SingletonFunction singletonFunction = SingletonFunction.Builder.create(this, "MySingletonFunction") .code(code) .handler("handler") .runtime(runtime) .uuid("uuid") // the properties below are optional .allowAllOutbound(false) .allowPublicSubnet(false) .architecture(architecture) .architectures(List.of(architecture)) .codeSigningConfig(codeSigningConfig) .currentVersionOptions(VersionOptions.builder() .codeSha256("codeSha256") .description("description") .maxEventAge(Duration.minutes(30)) .onFailure(destination) .onSuccess(destination) .provisionedConcurrentExecutions(123) .removalPolicy(RemovalPolicy.DESTROY) .retryAttempts(123) .build()) .deadLetterQueue(queue) .deadLetterQueueEnabled(false) .deadLetterTopic(topic) .description("description") .environment(Map.of( "environmentKey", "environment")) .environmentEncryption(key) .ephemeralStorageSize(size) .events(List.of(eventSource)) .filesystem(fileSystem) .functionName("functionName") .initialPolicy(List.of(policyStatement)) .insightsVersion(lambdaInsightsVersion) .lambdaPurpose("lambdaPurpose") .layers(List.of(layerVersion)) .logRetention(RetentionDays.ONE_DAY) .logRetentionRetryOptions(LogRetentionRetryOptions.builder() .base(Duration.minutes(30)) .maxRetries(123) .build()) .logRetentionRole(role) .maxEventAge(Duration.minutes(30)) .memorySize(123) .onFailure(destination) .onSuccess(destination) .profiling(false) .profilingGroup(profilingGroup) .reservedConcurrentExecutions(123) .retryAttempts(123) .role(role) .securityGroup(securityGroup) .securityGroups(List.of(securityGroup)) .timeout(Duration.minutes(30)) .tracing(Tracing.ACTIVE) .vpc(vpc) .vpcSubnets(SubnetSelection.builder() .availabilityZones(List.of("availabilityZones")) .onePerAz(false) .subnetFilters(List.of(subnetFilter)) .subnetGroupName("subnetGroupName") .subnetName("subnetName") .subnets(List.of(subnet)) .subnetType(SubnetType.ISOLATED) .build()) .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
SingletonFunction
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
SingletonFunction
(software.amazon.jsii.JsiiObjectRef objRef) SingletonFunction
(software.constructs.Construct scope, String id, SingletonFunctionProps props) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDependency
(@NotNull IDependable... up) Using node.addDependency() does not work on this method as the underlying lambda function is modeled as a singleton across the stack.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.void
addPermission
(String name, Permission permission) Adds a permission to the Lambda resource policy.void
dependOn
(IConstruct down) The SingletonFunction construct cannot be added as a dependency of another construct using node.addDependency().The architecture of this Lambda Function.protected Boolean
Whether the addPermission() call adds any permissions.Access the Connections object.Returns alambda.Version
which represents the current version of this singleton Lambda function.The ARN fo the function.The name of the function.The principal this Lambda Function is running as.Whether or not this Lambda function was bound to a VPC.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()
The IAM role associated with this function.The runtime environment for the Lambda function.Methods inherited from class software.amazon.awscdk.services.lambda.FunctionBase
addEventSource, addEventSourceMapping, addFunctionUrl, addFunctionUrl, addToRolePolicy, configureAsyncInvoke, considerWarningOnInvokeFunctionPermissions, 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
-
SingletonFunction
protected SingletonFunction(software.amazon.jsii.JsiiObjectRef objRef) -
SingletonFunction
protected SingletonFunction(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
SingletonFunction
@Stability(Stable) public SingletonFunction(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull SingletonFunctionProps props) - Parameters:
scope
- This parameter is required.id
- This parameter is required.props
- This parameter is required.
-
-
Method Details
-
addDependency
Using node.addDependency() does not work on this method as the underlying lambda function is modeled as a singleton across the stack. Use this method instead to declare dependencies.- Parameters:
up
- 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.
-
addPermission
Adds a permission to the Lambda resource policy.- Specified by:
addPermission
in interfaceIFunction
- Overrides:
addPermission
in classFunctionBase
- Parameters:
name
- This parameter is required.permission
- This parameter is required.- See Also:
-
dependOn
The SingletonFunction construct cannot be added as a dependency of another construct using node.addDependency(). Use this method instead to declare this as a dependency of another construct.- Parameters:
down
- This parameter is required.
-
getArchitecture
The architecture of this Lambda Function.- 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
-
getConnections
Access the Connections object.Will fail if not a VPC-enabled Lambda Function
- Specified by:
getConnections
in interfaceIConnectable
- Overrides:
getConnections
in classFunctionBase
-
getCurrentVersion
Returns alambda.Version
which represents the current version of this singleton 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.SingletonFunction
. -
getFunctionArn
The ARN fo the function.- Specified by:
getFunctionArn
in interfaceIClientVpnConnectionHandler
- Specified by:
getFunctionArn
in interfaceIFunction
- Specified by:
getFunctionArn
in classFunctionBase
-
getFunctionName
The name of the 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
-
getIsBoundToVpc
Whether or not this Lambda function was bound to a VPC.If this is is
false
, trying to access theconnections
object will fail.- Specified by:
getIsBoundToVpc
in interfaceIFunction
- Overrides:
getIsBoundToVpc
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 environment for the Lambda function. -
getRole
The IAM role associated with this function.Undefined if the function was imported without a role.
- Specified by:
getRole
in interfaceIFunction
- Specified by:
getRole
in classFunctionBase
-