Skip to content

Example Java Lambda Function Using Custom Base Image

License

Notifications You must be signed in to change notification settings

aleph0io/example-java-lambda-function

Repository files navigation

Example Java Lambda Function

Introduction

This is a (simple) example AWS Lambda function using my Custom Java Lambda Base Image. You can always find the base images in the ECR Public Gallery. Note that as of the time of this writing, the base image only supports x86_64, so build your images accordingly.

Build

You can build it using maven. (Don't forget to replace $AWS_ACCOUNT_ID and $AWS_REGION with your values.)

$ mvn -Daws.account=$AWS_ACCOUNT_ID -Daws.region=$AWS_REGION clean compile install

Next, you'd push your image to an ECR repository called example-java-lambda-function in your account. I assume you've already created it. Make sure it's in the right region! You also must have already set up authentication in your awscli instance.

$ aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com

Finally, you'd create a new Lambda function with your container. Then you can test it in the console:

AWS Console Test Input

AWS Console Test Output

Future Work

I may add a CloudFormation template using SAM to make running this example easier.