Looking for Senior AWSÂ Serverless Architects &Â Engineers?
Let's TalkYou can use your API 12 Million times per year and pay AWS $0
AWS Lambda
đ§ An AWS Lambda function is flexible:
- As of Nov. 2018, you can write in any language â even the 1959 language Cobol!
- You can trigger the code to run from a database action, an API query, a metric in CloudWatch, a 3rd party monitoring app, an IoT deviceâŚ
- Even though a Lambdaâs max timeout is 15 minutes, it can trigger another Lambda. So you can even do DNA sequencing with Lambda.
- Youâre not locked into AWS. A Lambda just has the core logic â no server configurations. Google Cloud, Azure, and IBM have cloud functions too.
đ¸ An AWS Lambda function can be cheap :
- You can run your code 1 Million times per month for free, forever. Thatâs enough for many businesses, especially startups.
- You only pay for the milliseconds itâs in use for, instead of paying 24/7 costs for a server, not to mention IT staff.
- AWS has been around since 2006 and has never raised costs. Prices keep falling dramatically.
đ An AWS Lambda function makes you agile:
- Even if it doesnât reduce your costs, because you have billions of users, the speed of development is worth it. Think of all the developer hours saved.
- Imagine how much faster you can try out ideas with customers.
đ And yes, a Lambda can run Spring Boot.
Get a Sample Spring Boot API Running in 5 Minutes
- Prerequisites.
- Clone the code from GitHub.
- Build it with Maven.
- Deploy it to AWS.
- đś Test it by going to the APIâs URL and getting back a JSON of dog names.
Prerequisites
- Install Node.
- Install the serverless CLI: npm -g install serverless
- Install the maven CLI. If you have brew, itâs brew install maven.
- Set up an AWS account.
- Save your AWS credentials locally.
đ Clone the Code đ
This was written by AWS Labs, and then I converted the Spring Boot Pet Store example from SAM to the Serverless Framework. I wrote about how that reduced deployment complexity by 97.4%.
đ Build It With Maven
đ Deploy the API
Watch out for the output in your command-line. You should see something like this:
âď¸ Test It
Paste that endpoint URL into your browser and add pets at the end, so .com/dev/pets. If itâs a success, then congratulations. If not, then leave a comment.
Anatomy of a Spring Boot Lambda
Just as with any Lambda, you can take advantage of CloudWatch Logs to print debugging messages. đ
The entry point to any Lambda accepts arguments, including the event that triggered it (the inputStream). This one is in the StreamLambdaHandler.java:
What kind of Java things have you done in Lambda?