You 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?