Amazon don’t make learning lambdas that straightforward, so I will give a quick tutorial on how to create a Java Lambda and make a HTTP GET on the lambda to get a response of Hello World.
- Register on Amazon Web Services https://aws.amazon.com/
- Open Eclipse
- Go File -> New -> Other
- There should be a folder after the AWS plugins have been installed into Eclipse
- AWS -> AWS Java Lambda Project
- Click next
- Fill in a project name
- Change input type to Custom (this produces a Hello World template)
- Click finish
Staying with Eclipse, right click on the Java file you are currently working on. Go down to AWS Lambda and go Upload Function to AWS Lambda.
Select the correct timezone and give it an appropriate name.
Click next, select an appropriate S3 bucket to store your Lambda in, if you do not have one, create one on the AWS console.
Editing the lambda
Once the lambda is up there, now you can start editing it.
You will need to send back a HTTP response, otherwise you will not be able to make a get on the lambda.
- change the handleRequest method return type to Map<String, String>
- have a key in the map called body, and the value called Hello World
- save it and upload to amazon as done before on setup
Exposing the Lambda to the outside world
Go to the AWS console. Then, go to Lambda. Then select functions.
Your function should be listed there at this point. Select it.
Go to Triggers and add API gateway. This will allow your Lambda to access the outside world. Configure the triggers accordingly.
On the AWS console, go to API gateway and select LambdaMicroservice.
On actions, select deploy API and set it to PROD.
On the side menu, click stages, then click prod dropdown icon.
There should be your function with GET, POST etc..
Select GET, then copy the URL into your browser window, and it should return hello world to the window.