App is deployed to AWS Lambda:
JAR with StreamLambdaHandler | Graal VM native binary with custom runtime | |
---|---|---|
Branch | master |
aws-lambda-graalvm |
URL | https://te60oj36jd.execute-api.eu-west-1.amazonaws.com/Prod/ | https://995oz2jt04.execute-api.eu-west-1.amazonaws.com/Prod/ |
Client application using this API:
Website URL | Github repository |
---|---|
https://ivarprudnikov.github.io/react-auth0-template/ | https://github.com/ivarprudnikov/react-auth0-template |
Example should serve as a template when necessary to write a small service which uses JWT tokens signed by Auth0 server.
Blog post explaining implementation - ivarprudnikov.com/micronaut-kotlin-jwt-secured-api-aws-lambda
JWT config (by using JWKS) is visible in application.yml. Controller endpoint then uses @Secured
annotation.
/
- returns statusUP
in plain text/me
- returns userio.micronaut.security.authentication.Authentication
in JSON response
Start Micronaut server
./gradlew run
Then to check status
curl http://localhost:8080
UP%
This requires Docker to be running locally and sam
CLI installed.
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-start-api.html
sam local start-api --template template.yaml --port 8080
....
Mounting ExampleFunction at http://127.0.0.1:8080/ [DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT]
Mounting ExampleFunction at http://127.0.0.1:8080/{proxy+} [DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT]
You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2020-03-02 22:16:20 * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
Instead of running the application and then trying to invoke API in the browser you could just invoke Lambda function with pre-built events:
sam local invoke --template template.yaml --event aws-test-events/options-me.json --skip-pull-image
Utilizing AWS Lambda to make sure I'm not paying for idle time.
Example micronaut implementations:
- https://github.com/micronaut-projects/micronaut-aws/tree/master/examples/api-gateway-example
- https://github.com/micronaut-guides/micronaut-function-aws-lambda Example micronaut implementations using Graal VM (native binaries):
- https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/micronaut/pet-store
- https://github.com/micronaut-guides/micronaut-creating-first-graal-app
-
Build jar
./gradlew clean build --info
-
Create
S3 bucket
where application version is going to be uploaded before deployed to Cloudformation:aws s3 mb s3://BUCKET_NAME
-
Package Lambda (uploads to S3):
sam package \ --output-template-file packaged.yaml \ --s3-bucket BUCKET_NAME
-
Create Cloudformation Stack and deploy your SAM resources.
sam deploy \ --template-file packaged.yaml \ --stack-name STACK_NAME \ --capabilities CAPABILITY_IAM
-
After deployment is complete you can run the following command to retrieve the API Gateway Endpoint URL:
aws cloudformation describe-stacks \ --stack-name STACK_NAME \ --query 'Stacks[].Outputs[?OutputKey==`ApiUrl`]' \ --output table
Below sam validate
requires AWS Credentials to be set up.
sam validate && LAMBDA_APP_NAME=auth0-micronaut-template bash build-deploy.sh
In order to delete our Serverless Application recently deployed you can use the following AWS CLI Command:
aws cloudformation delete-stack --stack-name STACK_NAME