In the Application.java file is created the ApplicationContext using singleton pattern and the ApplicationContext.getBean is encapsulated in the Application.getBean protecting the application context for been accessed from other classes.

In this BasicSample.java file the method doSomething uses the input string and returns a new string.

Deploying on AWS

The AWS Toolkit helps us on this step. The only thing we have to do is open the any .java file, open the context menu (right-click), chose “AWS Lambda” and then “Upload function to AWS Lambda…” option.

You will see the window below:

Chose the “Create a new Lambda function” option, type the name BasicSampleFunction and click “Next”.

In the window above, you must create a IAM role and a S3 Bucket for your function.

You also need to change the Memory to 512MB, because with less memory, the application takes longer during cold start.

Click Finish and wait until your function is deployed.

Running the Function

It’s time to test our work. Right click on any .java file, chose “AWS Lambda” and then “Run function on AWS Lambda…” option.

In the window below, type any text you want to pass to your lambda function and click “Invoke”

In the first execution, it will take some time to start your application (~ 3 sec).

If everything works fine, you will see the output in the console.

Troubleshooting

If you want to see the log of your call, you can go to the CloudWatch and click on the Log in the left menu.

Look for your function, the log should be /aws/lambda/FunctionName, click on it and a new window will appear.

Chose the first (or the only) Log Stream to see the log.

Conclusion

This is just a start point for the AWS Lambda, you can try some other frameworks instead of spring.

In the next post I’ll show how to create a API Gateway and call the lamba function.