An exemple for using serverless with aws and java
If you find my work useful, consider donating to support it :)
You can simply scan this QR code to get my Ethereum address
Start by creating a user with programmatic-access-only in AWS having the following roles
- AmazonS3FullAccess
- CloudWatchLogsFullAccess
- IAMFullAccess
- AWSLambdaFullAccess
- CloudFormationFullAccess
- AmazonAPIGatewayAdministrator
Install serverless
$ npm install -g serverless
Setup credentials with serverless
$ serverless config credentials --provider aws --key <key> --secret <secret>
We need to create a lambda layer that contains the java dependencies
$ cd serverless
$ mvn clean package
$ cd ../javalibs-layer
$ serverless deploy
Then deploy the serverless application
$ cd serverless
$ serverless deploy
if the dependencies was not changed you can simply build and deploy the project
$ cd serverless
$ mvn clean package
$ serverless deploy
You can test a function using
$ serverless invoke --function add-transaction --data '{"pathParameters":{"accountId":"123"},"body":"{\"amount\": 1234}"}'
To see logs use
$ serverless logs --function add-transaction
Via Curl
$ curl -X POST https://xxxx.execute-api.us-east-1.amazonaws.com/dev/accounts/123/transactions --data '{"amount":1234}'