Skip navigation links

Package software.amazon.awscdk.services.s3objectlambda

AWS::S3ObjectLambda Construct Library

See: Description

Package software.amazon.awscdk.services.s3objectlambda Description

AWS::S3ObjectLambda Construct Library

---

cfn-resources: Stable

All classes with the Cfn prefix in this module (CFN Resources) are always stable and safe to use.

cdk-constructs: Experimental

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


This construct library allows you to define S3 object lambda access points.

 import software.amazon.awscdk.services.lambda.*;
 import software.amazon.awscdk.services.s3.*;
 import software.amazon.awscdk.services.s3objectlambda.*;
 import software.amazon.awscdk.core.*;
 
 Stack stack = new Stack();
 Bucket bucket = new Bucket(stack, "MyBucket");
 Function handler = Function.Builder.create(stack, "MyFunction")
         .runtime(Runtime.NODEJS_14_X)
         .handler("index.handler")
         .code(Code.fromAsset("lambda.zip"))
         .build();
 AccessPoint.Builder.create(stack, "MyObjectLambda")
         .bucket(bucket)
         .handler(handler)
         .accessPointName("my-access-point")
         .payload(Map.of(
                 "prop", "value"))
         .build();
 

Handling range and part number requests

Lambdas are currently limited to only transforming GetObject requests. However, they can additionally support GetObject-Range and GetObject-PartNumber requests, which needs to be specified in the access point configuration:

 import software.amazon.awscdk.services.lambda.*;
 import software.amazon.awscdk.services.s3.*;
 import software.amazon.awscdk.services.s3objectlambda.*;
 import software.amazon.awscdk.core.*;
 
 Stack stack = new Stack();
 Bucket bucket = new Bucket(stack, "MyBucket");
 Function handler = Function.Builder.create(stack, "MyFunction")
         .runtime(Runtime.NODEJS_14_X)
         .handler("index.handler")
         .code(Code.fromAsset("lambda.zip"))
         .build();
 AccessPoint.Builder.create(stack, "MyObjectLambda")
         .bucket(bucket)
         .handler(handler)
         .accessPointName("my-access-point")
         .supportsGetObjectRange(true)
         .supportsGetObjectPartNumber(true)
         .build();
 

Pass additional data to Lambda function

You can specify an additional object that provides supplemental data to the Lambda function used to transform objects. The data is delivered as a JSON payload to the Lambda:

 import software.amazon.awscdk.services.lambda.*;
 import software.amazon.awscdk.services.s3.*;
 import software.amazon.awscdk.services.s3objectlambda.*;
 import software.amazon.awscdk.core.*;
 
 Stack stack = new Stack();
 Bucket bucket = new Bucket(stack, "MyBucket");
 Function handler = Function.Builder.create(stack, "MyFunction")
         .runtime(Runtime.NODEJS_14_X)
         .handler("index.handler")
         .code(Code.fromAsset("lambda.zip"))
         .build();
 AccessPoint.Builder.create(stack, "MyObjectLambda")
         .bucket(bucket)
         .handler(handler)
         .accessPointName("my-access-point")
         .payload(Map.of(
                 "prop", "value"))
         .build();
 
Skip navigation links