Disclaimer - This project should be considered a POC and has not been tested or verified for production use. If you decided to run this on production systems you do so at your own risk.
Make sure you have the following installed on your build machine before getting started.
- GraalVM
- AWS CLI
$ ./mvnw package
AWS Lambda Custom Runtimes require an executable file in the root directory named simply bootstrap
. This can be any executable file, for our case we're going to just use
a shell script to call our launcher that we created in the step above. This script will do nothing more than invoke our Java Runtime from the dist folder.
$ touch boostrap
Add the following commands to the bootstrap
#!/bin/sh
/opt/target/lambda
Note that the path we're using in our shell script is /opt
. When you create a Lambda Layer, as we'll do shortly, AWS Lambda copies all the runtime files to the /opt
directory. This directory is effectively the home directory for our custom runtime.
$ chmod +x bootstrap
In the root of the folder containing our bootstrap
and target/lambda
files, create a zip archive containing the artifacts.
$ zip -r function.zip bootstrap target/lambda
aws iam create-role \
--role-name lambda-role \
--path "/service-role/" \
--assume-role-policy-document file:///tmp/trust-policy.json
Where the file /tmp/trust-policy.json
contains:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
aws lambda publish-layer-version \
--layer-name vertx-native-example \
--zip-file fileb://function.zip
aws lambda delete-function --function-name vertxNativeTester
aws lambda create-function --function-name vertxNativeTester \
--zip-file fileb://function.zip --handler lambda.EchoLambda --runtime provided \
--role arn:aws:iam::985727241951:role/service-role/lambda-role
aws lambda update-function-configuration --function-name vertxNativeTester --layers arn:aws:lambda:eu-central-1:985727241951:layer:vertx-native-example:8
aws lambda invoke --function-name vertxNativeTester --payload '{"message":"Hello World"}' --log-type Tail response.txt | grep "LogResult"| awk -F'"' '{print $4}' | base64 --decode