Sample serverless application using Micronaut (Security, Data, AWS), API Gateway and GraalVM
- Micronaut 3.5.3
- SAM
- Cockroach
- TestContainers
- Java 11
micronaut-security-serverless-sample % make buildmicronaut-security-serverless-sample % make build-graalvmThis command starts the docker containers, sam local api and build the project.
micronaut-security-serverless-sample % make run1 - Configure intellij remote debugging.
2 - Execute this command
micronaut-security-serverless-sample % make debug3 - Send request
4 - Start debug
You can use docker exec to execute sql commands in local cockroach. After the first execution, use this command to insert role in table.
docker exec cockroach-db /cockroach/cockroach sql --insecure --database=security --execute="INSERT INTO public.tb_role (id, "type") VALUES(1, 'ROLE_USER');"curl -X "POST" "http://localhost:3000/users/register" \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"email": "user@gmail.com",
"password": "12345678"
}'curl -X "POST" "http://localhost:3000/login" \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"username": "user@gmail.com",
"password": "12345678"
}'curl -X "GET" "http://localhost:3000/users/profile" \
-H 'Content-Type: application/json; charset=utf-8' \
--header 'Authorization: Bearer {{access_token}}' http://localhost:80801 - For GraalVM compilations, create an aws lambda function with Amazon Linux 2 custom runtime.

2 - Upload the zip file generated by the build
micronaut-security-serverless-sample/build/libs/micronaut-security-serverless-sample-0.1-lambda.zip3 - Add the environment variables with cockroach database parameters.
You can create a free tier serverless cockroach database

2 - Map each route in the API gateway and enable lambda integration proxy

3 - Deploy API gateway stage
- Create user
curl -X "POST" "https://{api-gateway-alias}.execute-api.us-east-1.amazonaws.com/prod/users/register" \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"email": "user@gmail.com",
"password": "12345678"
}'- Authenticate user
curl -X "POST" "https://{api-gateway-alias}.execute-api.us-east-1.amazonaws.com/prod/login" \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"username": "user@gmail.com",
"password": "12345678"
}'- Get user profile
curl -X "GET" "https://{api-gateway-alias}.execute-api.us-east-1.amazonaws.com/prod/users/profile" \
-H 'Content-Type: application/json; charset=utf-8' \
--header 'Authorization: Bearer {{access_token}}' 


