This example demonstrates how to use Micronaut AWS API Gateway Proxy support and GraalVM to construct a custom runtime that runs native images or Lambda.
The Dockerfile
contains the build to build the native image and it can be built with:
$ docker build . -t greachconf-telegrambot
$ mkdir -p build
$ docker run --rm --entrypoint cat greachconf-telegrambot /home/application/function.zip > build/function.zip
Which will add the function deployment ZIP file to build/function.zip
. You can run function locally using SAM
$ docker build . -t greachconf-telegrambot
$ ./sam-local.sh
$ curl http://localhost:3000/ping
Or you can deploy it to AWS via the console or CLI:
aws lambda create-function --function-name greachconf-telegrambot \
--zip-file fileb://build/function.zip --handler function.handler --runtime provided \
--role ARN_OF_LAMBDA_ROLE
To create role for AWS Lambda, use following code:
The function can be invoked by sending an API Gateway Proxy request. For example:
aws lambda invoke --function-name greachconf-telegrambot --payload '{"resource": "/{proxy+}", "path": "/ping", "httpMethod": "GET"}' build/response.txt
cat build/response.txt
and response should be something like:
{"statusCode":200,"multiValueHeaders":{},"body":"{\"pong\":true, \"graal\": true}","isBase64Encoded":false}
Example controller responding with /ping are included in template.
You should replace the /ping
path entry with the URI the controller endpoint you wish to invoke.