Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

S3 Object Lambda


Stability: Stable

This is a stable example. It should successfully build out of the box

This example is built on Construct Libraries marked "Stable" and does not have any infrastructure prerequisites to build.


Overview

This is a Java CDK example to create a S3 Object Lambda. The main cloud infrastructure resources created with this example are:

  • an S3 Bucket;
  • a S3 Access Point;
  • an S3 Object Lambda Access Point;
  • a Lambda Function to process the GET object requests.

Once this example is deployed, any object uploaded in the bucket created will be available through the S3 Object Lambda Access Point. When trying to access an object through the S3 Object Lambda Access Point, a metadata output generated by the lambda function will be returned. The object metadata output generated by the lambda is similar to the following:

{
  "metadata": {
    "length": 1048576,
    "md5": "b6d81b360a5672d80c27430f39153e2c",
    "sha1": "3b71f43ff30f4b15b5cd85dd9e95ebc7e84eb5a3",
    "sha256": "30e14955ebf1352266dc2ff8067e68104607e750abb9d3b36582b8af909fcb58"
  }
}

Build

To build this example, you need to be in this example's infra directory. Then run the following:

  npm install -g aws-cdk
  npm install
  cdk synth

Note

In order to build this project you need Docker (and Docker Desktop if you want to use a GUI) installed. Moreover, the Docker daemon must be running while you execute the build or deploy commands. Unless the Docker daemon is running the Maven build of the lambda function (S3ObjectLambdaTransformer) will fail. This is required because the CDK will build the code for the lambda function locally in a Docker container. You should also create a virtual file share for the local /tmp directory (see Synchronized file shares). This can be done from Docker Desktop (Settings>Resources>File sharing).

Note

When you build this project for the first time, the required Docker image (sam/build-java17) will be pulled from AWS ECR. This will cause the first build to be slower. That is unless the required container image is already present on the system.

Deploy

To deploy this example, you need to be in this example's infra directory and run cdk deploy. This will deploy / redeploy the Stack to AWS. After the CDK deployment is successful, the URL of the S3 Object Lambda Access Point (the output named S3ObjectLambdaStack.s3ObjectLambdaAccessPointUrl) will be available in the terminal console. At this point, this URL can be used for testing. Copy the URL and paste it in the address bar of a browser. This will take you to the access point in the AWS management console (you need to be authenticated for that). From here you can access an S3 object to get the corresponding metadata (you need to have objects in the bucket for that).

Useful commands

  • mvn package compile and run tests
  • cdk ls list all stacks in the app
  • cdk synth emits the synthesized CloudFormation template
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk docs open CDK documentation