java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.core.Construct
software.amazon.awscdk.core.Resource
software.amazon.awscdk.services.cloudfront.experimental.EdgeFunction
All Implemented Interfaces:
IConstruct, IDependable, IResource, IConnectable, IGrantable, IFunction, IVersion, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:30:43.780Z") @Stability(Stable) public class EdgeFunction extends Resource implements IVersion
A Lambda@Edge function.

Convenience resource for requesting a Lambda function in the 'us-east-1' region for use with Lambda@Edge. Implements several restrictions enforced by Lambda@Edge.

Note that this construct requires that the 'us-east-1' region has been bootstrapped. See https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html or 'cdk bootstrap --help' for options.

Example:

 Bucket myBucket;
 // A Lambda@Edge function added to default behavior of a Distribution
 // and triggered on every request
 EdgeFunction myFunc = EdgeFunction.Builder.create(this, "MyFunction")
         .runtime(Runtime.NODEJS_14_X)
         .handler("index.handler")
         .code(Code.fromAsset(join(__dirname, "lambda-handler")))
         .build();
 Distribution.Builder.create(this, "myDist")
         .defaultBehavior(BehaviorOptions.builder()
                 .origin(new S3Origin(myBucket))
                 .edgeLambdas(List.of(EdgeLambda.builder()
                         .functionVersion(myFunc.getCurrentVersion())
                         .eventType(LambdaEdgeEventType.VIEWER_REQUEST)
                         .build()))
                 .build())
         .build();
 
  • Constructor Details

    • EdgeFunction

      protected EdgeFunction(software.amazon.jsii.JsiiObjectRef objRef)
    • EdgeFunction

      protected EdgeFunction(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • EdgeFunction

      @Stability(Stable) public EdgeFunction(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull EdgeFunctionProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • addAlias

      @Stability(Stable) @NotNull public Alias addAlias(@NotNull String aliasName, @Nullable AliasOptions options)
      Defines an alias for this version.

      Specified by:
      addAlias in interface IVersion
      Parameters:
      aliasName - This parameter is required.
      options -
    • addAlias

      @Stability(Stable) @NotNull public Alias addAlias(@NotNull String aliasName)
      Defines an alias for this version.

      Specified by:
      addAlias in interface IVersion
      Parameters:
      aliasName - This parameter is required.
    • addEventSource

      @Stability(Stable) public void addEventSource(@NotNull IEventSource source)
      Adds an event source to this function.

      Specified by:
      addEventSource in interface IFunction
      Parameters:
      source - This parameter is required.
    • addEventSourceMapping

      @Stability(Stable) @NotNull public EventSourceMapping addEventSourceMapping(@NotNull String id, @NotNull EventSourceMappingOptions options)
      Adds an event source that maps to this AWS Lambda function.

      Specified by:
      addEventSourceMapping in interface IFunction
      Parameters:
      id - This parameter is required.
      options - This parameter is required.
    • addFunctionUrl

      @Stability(Stable) @NotNull public FunctionUrl addFunctionUrl(@Nullable FunctionUrlOptions options)
      Adds a url to this lambda function.

      Specified by:
      addFunctionUrl in interface IFunction
      Parameters:
      options -
    • addFunctionUrl

      @Stability(Stable) @NotNull public FunctionUrl addFunctionUrl()
      Adds a url to this lambda function.
      Specified by:
      addFunctionUrl in interface IFunction
    • addPermission

      @Stability(Stable) public void addPermission(@NotNull String id, @NotNull Permission permission)
      Adds a permission to the Lambda resource policy.

      Specified by:
      addPermission in interface IFunction
      Parameters:
      id - This parameter is required.
      permission - This parameter is required.
      See Also:
    • addToRolePolicy

      @Stability(Stable) public void addToRolePolicy(@NotNull PolicyStatement statement)
      Adds a statement to the IAM role assumed by the instance.

      Specified by:
      addToRolePolicy in interface IFunction
      Parameters:
      statement - This parameter is required.
    • configureAsyncInvoke

      @Stability(Stable) public void configureAsyncInvoke(@NotNull EventInvokeConfigOptions options)
      Configures options for asynchronous invocation.

      Specified by:
      configureAsyncInvoke in interface IFunction
      Parameters:
      options - This parameter is required.
    • grantInvoke

      @Stability(Stable) @NotNull public Grant grantInvoke(@NotNull IGrantable identity)
      Grant the given identity permissions to invoke this Lambda.

      Specified by:
      grantInvoke in interface IFunction
      Parameters:
      identity - This parameter is required.
    • grantInvokeUrl

      @Stability(Stable) @NotNull public Grant grantInvokeUrl(@NotNull IGrantable identity)
      Grant the given identity permissions to invoke this Lambda Function URL.

      Specified by:
      grantInvokeUrl in interface IFunction
      Parameters:
      identity - This parameter is required.
    • metric

      @Stability(Stable) @NotNull public Metric metric(@NotNull String metricName, @Nullable MetricOptions props)
      Return the given named metric for this Lambda Return the given named metric for this Function.

      Specified by:
      metric in interface IFunction
      Parameters:
      metricName - This parameter is required.
      props -
    • metric

      @Stability(Stable) @NotNull public Metric metric(@NotNull String metricName)
      Return the given named metric for this Lambda Return the given named metric for this Function.

      Specified by:
      metric in interface IFunction
      Parameters:
      metricName - This parameter is required.
    • metricDuration

      @Stability(Stable) @NotNull public Metric metricDuration(@Nullable MetricOptions props)
      Metric for the Duration of this Lambda How long execution of this Lambda takes.

      Average over 5 minutes

      Specified by:
      metricDuration in interface IFunction
      Parameters:
      props -
    • metricDuration

      @Stability(Stable) @NotNull public Metric metricDuration()
      Metric for the Duration of this Lambda How long execution of this Lambda takes.

      Average over 5 minutes

      Specified by:
      metricDuration in interface IFunction
    • metricErrors

      @Stability(Stable) @NotNull public Metric metricErrors(@Nullable MetricOptions props)
      How many invocations of this Lambda fail.

      Sum over 5 minutes

      Specified by:
      metricErrors in interface IFunction
      Parameters:
      props -
    • metricErrors

      @Stability(Stable) @NotNull public Metric metricErrors()
      How many invocations of this Lambda fail.

      Sum over 5 minutes

      Specified by:
      metricErrors in interface IFunction
    • metricInvocations

      @Stability(Stable) @NotNull public Metric metricInvocations(@Nullable MetricOptions props)
      Metric for the number of invocations of this Lambda How often this Lambda is invoked.

      Sum over 5 minutes

      Specified by:
      metricInvocations in interface IFunction
      Parameters:
      props -
    • metricInvocations

      @Stability(Stable) @NotNull public Metric metricInvocations()
      Metric for the number of invocations of this Lambda How often this Lambda is invoked.

      Sum over 5 minutes

      Specified by:
      metricInvocations in interface IFunction
    • metricThrottles

      @Stability(Stable) @NotNull public Metric metricThrottles(@Nullable MetricOptions props)
      Metric for the number of throttled invocations of this Lambda How often this Lambda is throttled.

      Sum over 5 minutes

      Specified by:
      metricThrottles in interface IFunction
      Parameters:
      props -
    • metricThrottles

      @Stability(Stable) @NotNull public Metric metricThrottles()
      Metric for the number of throttled invocations of this Lambda How often this Lambda is throttled.

      Sum over 5 minutes

      Specified by:
      metricThrottles in interface IFunction
    • getArchitecture

      @Stability(Stable) @NotNull public Architecture getArchitecture()
      The system architectures compatible with this lambda function.
      Specified by:
      getArchitecture in interface IFunction
    • getConnections

      @Stability(Stable) @NotNull public Connections getConnections()
      Not supported.

      Connections are only applicable to VPC-enabled functions.

      Specified by:
      getConnections in interface IConnectable
    • getCurrentVersion

      @Stability(Stable) @NotNull public IVersion getCurrentVersion()
      Convenience method to make EdgeFunction conform to the same interface as Function.
    • getEdgeArn

      @Stability(Stable) @NotNull public String getEdgeArn()
      The ARN of the version for Lambda@Edge.
      Specified by:
      getEdgeArn in interface IVersion
    • getFunctionArn

      @Stability(Stable) @NotNull public String getFunctionArn()
      The ARN of the function.
      Specified by:
      getFunctionArn in interface IFunction
    • getFunctionName

      @Stability(Stable) @NotNull public String getFunctionName()
      The name of the function.
      Specified by:
      getFunctionName in interface IFunction
    • getGrantPrincipal

      @Stability(Stable) @NotNull public IPrincipal getGrantPrincipal()
      The principal to grant permissions to.
      Specified by:
      getGrantPrincipal in interface IGrantable
    • getIsBoundToVpc

      @Stability(Stable) @NotNull public Boolean getIsBoundToVpc()
      Whether or not this Lambda function was bound to a VPC.

      If this is is false, trying to access the connections object will fail.

      Specified by:
      getIsBoundToVpc in interface IFunction
    • getLambda

      @Stability(Stable) @NotNull public IFunction getLambda()
      The underlying AWS Lambda function.
      Specified by:
      getLambda in interface IVersion
    • getLatestVersion

      @Stability(Stable) @NotNull public IVersion getLatestVersion()
      The $LATEST version of this function.

      Note that this is reference to a non-specific AWS Lambda version, which means the function this version refers to can return different results in different invocations.

      To obtain a reference to an explicit version which references the current function configuration, use lambdaFunction.currentVersion instead.

      Specified by:
      getLatestVersion in interface IFunction
    • getPermissionsNode

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

      @Stability(Stable) @NotNull public List<String> getResourceArnsForGrantInvoke()
      The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().

      This property is for cdk modules to consume only. You should not need to use this property. Instead, use grantInvoke() directly.

      Specified by:
      getResourceArnsForGrantInvoke in interface IFunction
    • getVersion

      @Stability(Stable) @NotNull public String getVersion()
      The most recently deployed version of this function.
      Specified by:
      getVersion in interface IVersion
    • getRole

      @Stability(Stable) @Nullable public IRole getRole()
      The IAM role associated with this function.
      Specified by:
      getRole in interface IFunction