Creating a ‘batch’ app with AWS Lambda and Spring Boot and run it for FREE
Tags: springboot, awslambda, serveless, java
Published: 2023-09-18 00:50:53

---
title: Creating a ‘batch’ app with AWS Lambda and Spring Boot and run it for FREE
published: true
date: 2023-04-25 01:56:09 UTC
tags: springboot,awslambda,serveless,java
canonical_url: https://medium.com/@paulboeck/creating-a-batch-app-with-aws-lambda-and-spring-boot-and-run-it-for-free-cf3654521d1
---

### Create a ‘batch’ app with AWS Lambda and Spring Boot and run it for FREE

I know, it sounds a bit crazy to use an AWS Lambda function for workloads that typically run in ‘batch’ mode, but there are some compelling reasons to do so. One reason is that, as a serverless technology, AWS Lambda lets you focus on implementing your workload without having to worry about the infrastructure on which it’s running. However, I think the most compelling reason reason is cost. If you have workloads that you can keep under the 15 minute limit of a Lambda function, or if you have a multi-step workload that can be broken into smaller (quicker) parts, you can set up one or more Lambda functions that run on a schedule. Depending on how often your workload needs to run, you may be able to get away with paying $0 for your compute resources!

![Cartoon picture of a man in a suit and bowtie winking, and holding a sign that says FREE](https://cdn-images-1.medium.com/max/400/0*ElfFHacBnW4iODc2.jpg)

It may also sound a bit crazy to run a Spring Boot app as a Lambda function. After all, Spring isn’t exactly a lightweight framework. I would probably not recommend setting up a Spring Boot enabled Lambda for public facing apps or APIs that require sub-second response times. However, for certain workflows where there’s no client waiting on a quick response, the setup I’m going to walk you through here can be pretty slick, and cheap. Did I mention cheap?

The application I’m going to walk you through is a pretty contrived example of something that an organization might actually need to do. I’m going to show you how to create a process that runs once per day to retrieve weather statistics from a public API and store that data in a database. The idea being that someone or some process will use that data at some point to run queries, do analytics, create data visualizations, or something else I haven’t thought of. Maybe in a future article, I’ll come up with some grandiose idea of what to do with all the data this application could gather over time. Let me know if you have any ideas!

My intention is to show you how to implement this application in Java, running as an AWS Lambda function that stores data in a MySQL RDS instance. In future articles, I plan to begin evolving parts of this implementation to show some different options like splitting this process into multiple Lambda functions, moving the RDS instance into a private VPC/subnet, and using S3 or DynamoDB to store the data. I also plan to explore using AWS Batch in place of the Lambda function. Eventually, I’d like to get to the point of showing you how to use some of the AWS data engineering services like AWS Glue, Athena, and others. There are so many AWS services that I could probably go on for years :)

Since there are a fair number of pieces that are going to be required to implement this system in a way that’s secure, maintainable, and testable, I’m not going to be able to cover them all in one article. So, I’m creating this article for you to use as as a jumping off point to explore each phase of the implementation. I’ll link each article from here so you’ll have access to all the details of creating this application. The [GitHub repository](https://github.com/paulboeck/medium-weather-data-collector-java-lambda-rds) for this little weather data collector app is [here](https://github.com/paulboeck/medium-weather-data-collector-java-lambda-rds). Feel free to clone or fork the repository to follow along.

Here’s the list of detailed articles in the order that I think it makes sense to read/implement them. Articles that I’ve already written have links to them. The others are still in the works. So if you want to follow along with this little journey, bookmark this particular article because I’ll keep updating it with links to all the goodies.

- [Configure Terraform to set up (and tear down) your MySQL RDS instance](https://medium.com/@paulboeck/create-an-aws-rds-instance-with-terraform-e6bb9014dcde?source=friends_link&sk=691392c900b658b730d56d6f2fb75a4e)
- [Configure Terraform to store your database credentials securely](https://medium.com/@paulboeck/how-to-store-your-db-credentials-in-secrets-manager-using-terraform-d2daeb0cbabc?source=friends_link&sk=4431aa41c93e265c1e66fec85f3a37e5)
- [Configure AWS SAM to deploy your Lambda function and associated resources](https://medium.com/@paulboeck/deploying-an-aws-lambda-with-sam-d8dc2be798e3?source=friends_link&sk=6b50fc2b83a642898464360f39a32bdf) or ditch SAM and CloudFormation and [deploy your Lambda function using Terraform](https://medium.com/@paulboeck/goodbye-cloudformation-4c9623d37fb4?source=friends_link&sk=63cc4f22cf11c16a96f547c96b15eeed)
- [Modify your Lambda function to connect to MySQL using credentials from AWS Secrets Manager](https://medium.com/@paulboeck/aws-lambda-tutorial-using-secrets-manager-and-java-sdk-to-connect-to-mysql-8fcf3550dd86?source=friends_link&sk=deb569993db42885b2bd73be8ec1f721)
- [Configure your Lambda function as a Spring Boot Application](https://medium.com/@paulboeck/configure-your-aws-lambda-function-with-spring-boot-357846fe5878?source=friends_link&sk=f5c85ba7ab311a55338cb9221cdab09e)
- [Implement best practice structured JSON logging](https://medium.com/@paulboeck/66d69bd7a4d9?source=friends_link&sk=56017145ca245cb1d0e88e2bd57a2116)
- [Use Spring Data JPA to persist weather data to MySQL](https://medium.com/@paulboeck/persisting-data-to-mysql-with-spring-data-jpa-28a296b4adb7?source=friends_link&sk=9775220d0035b9d943186bfa713e3062)