Class Function

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
All Implemented Interfaces:
IResource, IClientVpnConnectionHandler, IConnectable, IGrantable, IFunction, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable
Direct Known Subclasses:
DockerImageFunction, GoFunction, NodejsFunction, PythonFunction, TriggerFunction

@Generated(value="jsii-pacmak/1.94.0 (build b380f01)", date="2024-02-23T02:06:34.526Z") @Stability(Stable) public class Function extends FunctionBase
Deploys a file from inside the construct library as a function.

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_18_X)
         .handler("index.handler")
         .code(Code.fromAsset(join(__dirname, "lambda-handler")))
         .build();
 
  • 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 the AWS::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.

      For Function.addPermissions() to work on this imported lambda, make sure that is in the same account and region as the stack you are importing it into.

      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.

      For Function.addPermissions() to work on this imported lambda, set the sameEnvironment property to true if this imported lambda is in the same account and region as the stack you are importing it into.

      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

      @Stability(Stable) @NotNull public static Metric metricAll(@NotNull String metricName)
      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

      @Stability(Stable) @NotNull public static Metric metricAllConcurrentExecutions()
      Metric for the number of concurrent executions across all Lambdas.

      Default: max over 5 minutes

    • metricAllDuration

      @Stability(Stable) @NotNull public static Metric metricAllDuration(@Nullable MetricOptions props)
      Metric for the Duration executing all Lambdas.

      Default: average over 5 minutes

      Parameters:
      props -
    • metricAllDuration

      @Stability(Stable) @NotNull public static Metric metricAllDuration()
      Metric for the Duration executing all Lambdas.

      Default: average over 5 minutes

    • metricAllErrors

      @Stability(Stable) @NotNull public static Metric metricAllErrors(@Nullable MetricOptions props)
      Metric for the number of Errors executing all Lambdas.

      Default: sum over 5 minutes

      Parameters:
      props -
    • metricAllErrors

      @Stability(Stable) @NotNull public static Metric 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

      @Stability(Stable) @NotNull public static Metric metricAllInvocations()
      Metric for the number of invocations of all Lambdas.

      Default: sum over 5 minutes

    • metricAllThrottles

      @Stability(Stable) @NotNull public static Metric metricAllThrottles(@Nullable MetricOptions props)
      Metric for the number of throttled invocations of all Lambdas.

      Default: sum over 5 minutes

      Parameters:
      props -
    • metricAllThrottles

      @Stability(Stable) @NotNull public static Metric 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

      @Stability(Stable) @NotNull public static Metric 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

      @Stability(Stable) @NotNull public Alias addAlias(@NotNull String aliasName)
      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

      @Stability(Stable) public void addLayers(@NotNull @NotNull ILayerVersion... layers)
      Adds one or more Lambda Layers to this Lambda function.

      Parameters:
      layers - the layers to be added. This parameter is required.
    • invalidateVersionBasedOn

      @Stability(Stable) public void invalidateVersionBasedOn(@NotNull String x)
      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.

      Parameters:
      x - This parameter is required.
    • getArchitecture

      @Stability(Stable) @NotNull public Architecture getArchitecture()
      The architecture of this Lambda Function (this is an optional attribute and defaults to X86_64).
      Specified by:
      getArchitecture in interface IFunction
      Specified by:
      getArchitecture in class FunctionBase
    • getCanCreatePermissions

      @Stability(Stable) @NotNull protected Boolean 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 class FunctionBase
    • getCurrentVersion

      @Stability(Stable) @NotNull public Version getCurrentVersion()
      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.

    • getFunctionArn

      @Stability(Stable) @NotNull public String getFunctionArn()
      ARN of this function.
      Specified by:
      getFunctionArn in interface IClientVpnConnectionHandler
      Specified by:
      getFunctionArn in interface IFunction
      Specified by:
      getFunctionArn in class FunctionBase
    • getFunctionName

      @Stability(Stable) @NotNull public String getFunctionName()
      Name of this function.
      Specified by:
      getFunctionName in interface IClientVpnConnectionHandler
      Specified by:
      getFunctionName in interface IFunction
      Specified by:
      getFunctionName in class FunctionBase
    • getGrantPrincipal

      @Stability(Stable) @NotNull public IPrincipal getGrantPrincipal()
      The principal this Lambda Function is running as.
      Specified by:
      getGrantPrincipal in interface IGrantable
      Specified by:
      getGrantPrincipal in class FunctionBase
    • getLogGroup

      @Stability(Stable) @NotNull public ILogGroup 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

      @Stability(Stable) @NotNull public software.constructs.Node getPermissionsNode()
      The construct node where permissions are attached.
      Specified by:
      getPermissionsNode in interface IFunction
      Specified by:
      getPermissionsNode in class FunctionBase
    • getResourceArnsForGrantInvoke

      @Stability(Stable) @NotNull public List<String> getResourceArnsForGrantInvoke()
      The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().
      Specified by:
      getResourceArnsForGrantInvoke in interface IFunction
      Specified by:
      getResourceArnsForGrantInvoke in class FunctionBase
    • getRuntime

      @Stability(Stable) @NotNull public Runtime getRuntime()
      The runtime configured for this lambda.
    • getDeadLetterQueue

      @Stability(Stable) @Nullable public IQueue getDeadLetterQueue()
      The DLQ (as queue) associated with this Lambda Function (this is an optional attribute).
    • getDeadLetterTopic

      @Stability(Stable) @Nullable public ITopic getDeadLetterTopic()
      The DLQ (as topic) associated with this Lambda Function (this is an optional attribute).
    • getRole

      @Stability(Stable) @Nullable public IRole getRole()
      Execution role associated with this function.
      Specified by:
      getRole in interface IFunction
      Specified by:
      getRole in class FunctionBase
    • getTimeout

      @Stability(Stable) @Nullable public Duration getTimeout()
      The timeout configured for this lambda.