Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aleph0io/example-java-lambda-function
Example Java Lambda Function Using Custom Base Image
https://github.com/aleph0io/example-java-lambda-function
aws-lambda java
Last synced: about 2 months ago
JSON representation
Example Java Lambda Function Using Custom Base Image
- Host: GitHub
- URL: https://github.com/aleph0io/example-java-lambda-function
- Owner: aleph0io
- License: apache-2.0
- Created: 2022-07-23T13:48:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-15T15:04:53.000Z (12 months ago)
- Last Synced: 2024-04-25T07:03:23.617Z (8 months ago)
- Topics: aws-lambda, java
- Language: Java
- Homepage:
- Size: 354 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Example Java Lambda Function
## Introduction
This is a (simple) example AWS Lambda function using my [Custom Java Lambda Base Image](https://github.com/aleph0io/aws-lambda-java-base-images). You can always find the base images in the [ECR Public Gallery](https://gallery.ecr.aws/aleph0io/lambda/java). 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](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-images.html). Then you can test it in the console:
![AWS Console Test Input](/test-input.png)
![AWS Console Test Output](/test-output.png)
## Future Work
I may add a CloudFormation template using SAM to make running this example easier.