limcheekin / micronaut-aws-graphql-jpa

Micronaut AWS Lambda, GraphQL, JPA, GraalVM Sample App

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Micronaut + GraalVM Native + AWS Lambda Custom Runtime

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 micronaut-aws-graphql-jpa
$ mkdir -p build
$ docker run --rm --entrypoint cat micronaut-aws-graphql-jpa  /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 micronaut-aws-graphql-jpa
$ ./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 micronaut-aws-graphql-jpa \
--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 micronaut-aws-graphql-jpa --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.

About

Micronaut AWS Lambda, GraphQL, JPA, GraalVM Sample App

License:Apache License 2.0


Languages

Language:Java 61.4%Language:Shell 22.0%Language:Dockerfile 16.6%