@Generated(value="jsii-pacmak/1.63.2 (build a8a8833)", date="2022-08-17T17:31:15.820Z") public class Function extends FunctionBase
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();
Modifier and Type | Class and Description |
---|---|
static class |
Function.Builder
A fluent builder for
Function . |
IFunction.Jsii$Default
IClientVpnConnectionHandler.Jsii$Default
Modifier | Constructor and Description |
---|---|
protected |
Function(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) |
protected |
Function(software.amazon.jsii.JsiiObjectRef objRef) |
|
Function(software.constructs.Construct scope,
java.lang.String id,
FunctionProps props) |
Modifier and Type | Method and Description |
---|---|
Alias |
addAlias(java.lang.String aliasName)
Defines an alias for this function.
|
Alias |
addAlias(java.lang.String aliasName,
AliasOptions options)
Defines an alias for this function.
|
Function |
addEnvironment(java.lang.String key,
java.lang.String value)
Adds an environment variable to this Lambda function.
|
Function |
addEnvironment(java.lang.String key,
java.lang.String value,
EnvironmentOptions options)
Adds an environment variable to this Lambda function.
|
void |
addLayers(ILayerVersion... layers)
Adds one or more Lambda Layers to this Lambda function.
|
Version |
addVersion(java.lang.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. Instead, use
`this.currentVersion` to obtain a reference to a version resource that gets
automatically recreated when the function configuration (or code) changes.
|
Version |
addVersion(java.lang.String name,
java.lang.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, use
`this.currentVersion` to obtain a reference to a version resource that gets
automatically recreated when the function configuration (or code) changes.
|
Version |
addVersion(java.lang.String name,
java.lang.String codeSha256,
java.lang.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, use
`this.currentVersion` to obtain a reference to a version resource that gets
automatically recreated when the function configuration (or code) changes.
|
Version |
addVersion(java.lang.String name,
java.lang.String codeSha256,
java.lang.String description,
java.lang.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, use
`this.currentVersion` to obtain a reference to a version resource that gets
automatically recreated when the function configuration (or code) changes.
|
Version |
addVersion(java.lang.String name,
java.lang.String codeSha256,
java.lang.String description,
java.lang.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. Instead, use
`this.currentVersion` to obtain a reference to a version resource that gets
automatically recreated when the function configuration (or code) changes.
|
static void |
classifyVersionProperty(java.lang.String propertyName,
java.lang.Boolean locked)
Record whether specific properties in the `AWS::Lambda::Function` resource should also be associated to the Version resource.
|
static IFunction |
fromFunctionArn(software.constructs.Construct scope,
java.lang.String id,
java.lang.String functionArn)
Import a lambda function into the CDK using its ARN.
|
static IFunction |
fromFunctionAttributes(software.constructs.Construct scope,
java.lang.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,
java.lang.String id,
java.lang.String functionName)
Import a lambda function into the CDK using its name.
|
Architecture |
getArchitecture()
The architecture of this Lambda Function (this is an optional attribute and defaults to X86_64).
|
protected java.lang.Boolean |
getCanCreatePermissions()
Whether the addPermission() call adds any permissions.
|
Version |
getCurrentVersion()
Returns a `lambda.Version` which represents the current version of this Lambda function.
|
IQueue |
getDeadLetterQueue()
The DLQ (as queue) associated with this Lambda Function (this is an optional attribute).
|
ITopic |
getDeadLetterTopic()
The DLQ (as topic) associated with this Lambda Function (this is an optional attribute).
|
java.lang.String |
getFunctionArn()
ARN of this function.
|
java.lang.String |
getFunctionName()
Name of this function.
|
IPrincipal |
getGrantPrincipal()
The principal this Lambda Function is running as.
|
ILogGroup |
getLogGroup()
The LogGroup where the Lambda function's logs are made available.
|
ConstructNode |
getPermissionsNode()
The construct node where permissions are attached.
|
java.util.List<java.lang.String> |
getResourceArnsForGrantInvoke()
The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().
|
IRole |
getRole()
Execution role associated with this function.
|
Runtime |
getRuntime()
The runtime configured for this lambda.
|
Duration |
getTimeout()
The timeout configured for this lambda.
|
static Metric |
metricAll(java.lang.String metricName)
Return the given named metric for this Lambda.
|
static Metric |
metricAll(java.lang.String metricName,
MetricOptions props)
Return the given named metric for this Lambda.
|
static Metric |
metricAllConcurrentExecutions()
Metric for the number of concurrent executions across all Lambdas.
|
static Metric |
metricAllConcurrentExecutions(MetricOptions props)
Metric for the number of concurrent executions across all Lambdas.
|
static Metric |
metricAllDuration()
Metric for the Duration executing all Lambdas.
|
static Metric |
metricAllDuration(MetricOptions props)
Metric for the Duration executing all Lambdas.
|
static Metric |
metricAllErrors()
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 |
metricAllInvocations()
Metric for the number of invocations of all Lambdas.
|
static Metric |
metricAllInvocations(MetricOptions props)
Metric for the number of invocations of all Lambdas.
|
static Metric |
metricAllThrottles()
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 |
metricAllUnreservedConcurrentExecutions()
Metric for the number of unreserved concurrent executions across all Lambdas.
|
static Metric |
metricAllUnreservedConcurrentExecutions(MetricOptions props)
Metric for the number of unreserved concurrent executions across all Lambdas.
|
addEventSource, addEventSourceMapping, addFunctionUrl, addFunctionUrl, addPermission, addToRolePolicy, configureAsyncInvoke, considerWarningOnInvokeFunctionPermissions, getConnections, getIsBoundToVpc, getLatestVersion, grantInvoke, grantInvokeUrl, metric, metric, metricDuration, metricDuration, metricErrors, metricErrors, metricInvocations, metricInvocations, metricThrottles, metricThrottles, warnInvokeFunctionPermissions
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isResource
getNode, isConstruct, onPrepare, onSynthesize, onValidate, prepare, synthesize, validate
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
applyRemovalPolicy, getEnv, getStack
getNode
protected Function(software.amazon.jsii.JsiiObjectRef objRef)
protected Function(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
public Function(software.constructs.Construct scope, java.lang.String id, FunctionProps props)
scope
- This parameter is required.id
- This parameter is required.props
- This parameter is required.public static void classifyVersionProperty(java.lang.String propertyName, java.lang.Boolean locked)
See 'currentVersion' section in the module README for more details.
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.public static IFunction fromFunctionArn(software.constructs.Construct scope, java.lang.String id, java.lang.String functionArn)
scope
- This parameter is required.id
- This parameter is required.functionArn
- This parameter is required.public static IFunction fromFunctionAttributes(software.constructs.Construct scope, java.lang.String id, FunctionAttributes attrs)
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.public static IFunction fromFunctionName(software.constructs.Construct scope, java.lang.String id, java.lang.String functionName)
scope
- This parameter is required.id
- This parameter is required.functionName
- This parameter is required.public static Metric metricAll(java.lang.String metricName, MetricOptions props)
metricName
- This parameter is required.props
- public static Metric metricAll(java.lang.String metricName)
metricName
- This parameter is required.public static Metric metricAllConcurrentExecutions(MetricOptions props)
Default: max over 5 minutes
props
- public static Metric metricAllConcurrentExecutions()
Default: max over 5 minutes
public static Metric metricAllDuration(MetricOptions props)
Default: average over 5 minutes
props
- public static Metric metricAllDuration()
Default: average over 5 minutes
public static Metric metricAllErrors(MetricOptions props)
Default: sum over 5 minutes
props
- public static Metric metricAllErrors()
Default: sum over 5 minutes
public static Metric metricAllInvocations(MetricOptions props)
Default: sum over 5 minutes
props
- public static Metric metricAllInvocations()
Default: sum over 5 minutes
public static Metric metricAllThrottles(MetricOptions props)
Default: sum over 5 minutes
props
- public static Metric metricAllThrottles()
Default: sum over 5 minutes
public static Metric metricAllUnreservedConcurrentExecutions(MetricOptions props)
Default: max over 5 minutes
props
- public static Metric metricAllUnreservedConcurrentExecutions()
Default: max over 5 minutes
public Alias addAlias(java.lang.String aliasName, AliasOptions options)
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();
aliasName
- The name of the alias. This parameter is required.options
- Alias options.public Alias addAlias(java.lang.String aliasName)
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();
aliasName
- The name of the alias. This parameter is required.public Function addEnvironment(java.lang.String key, java.lang.String value, EnvironmentOptions options)
If this is a ref to a Lambda function, this operation results in a no-op.
key
- The environment variable key. This parameter is required.value
- The environment variable's value. This parameter is required.options
- Environment variable options.public Function addEnvironment(java.lang.String key, java.lang.String value)
If this is a ref to a Lambda function, this operation results in a no-op.
key
- The environment variable key. This parameter is required.value
- The environment variable's value. This parameter is required.public void addLayers(ILayerVersion... layers)
layers
- the layers to be added. This parameter is required.@Deprecated public Version addVersion(java.lang.String name, java.lang.String codeSha256, java.lang.String description, java.lang.Number provisionedExecutions, EventInvokeConfigOptions asyncInvokeConfig)
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.
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.@Deprecated public Version addVersion(java.lang.String name, java.lang.String codeSha256, java.lang.String description, java.lang.Number provisionedExecutions)
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.
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.@Deprecated public Version addVersion(java.lang.String name, java.lang.String codeSha256, java.lang.String description)
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.
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.@Deprecated public Version addVersion(java.lang.String name, java.lang.String codeSha256)
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.
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.@Deprecated public Version addVersion(java.lang.String name)
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.
name
- A unique name for this version. This parameter is required.public Architecture getArchitecture()
getArchitecture
in interface IFunction
getArchitecture
in class FunctionBase
protected java.lang.Boolean getCanCreatePermissions()
True for new Lambdas, false for version $LATEST and imported Lambdas from different accounts.
getCanCreatePermissions
in class FunctionBase
public Version getCurrentVersion()
You can specify options for this version using the currentVersionOptions
prop when initializing the lambda.Function
.
public java.lang.String getFunctionArn()
getFunctionArn
in interface IClientVpnConnectionHandler
getFunctionArn
in interface IFunction
getFunctionArn
in class FunctionBase
public java.lang.String getFunctionName()
getFunctionName
in interface IClientVpnConnectionHandler
getFunctionName
in interface IFunction
getFunctionName
in class FunctionBase
public IPrincipal getGrantPrincipal()
getGrantPrincipal
in interface IGrantable
getGrantPrincipal
in class FunctionBase
public ILogGroup getLogGroup()
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.
public ConstructNode getPermissionsNode()
getPermissionsNode
in interface IFunction
getPermissionsNode
in class FunctionBase
public java.util.List<java.lang.String> getResourceArnsForGrantInvoke()
getResourceArnsForGrantInvoke
in interface IFunction
getResourceArnsForGrantInvoke
in class FunctionBase
public Runtime getRuntime()
public IQueue getDeadLetterQueue()
public ITopic getDeadLetterTopic()
public IRole getRole()
getRole
in interface IFunction
getRole
in class FunctionBase
public Duration getTimeout()