Code Monkey home page Code Monkey logo

spring-serverless-aws's Introduction

Serverless Rest API Architecture

Serverless

1. Introduction

Let's discuss the benefits of using AWS Lambda and Spring Boot 3 before we begin. You're probably accustomed to packaging your programmes as JAR files and distributing them to servers. You might even deploy the application to Kubernetes in a containerised form using Docker.

Scalability, security, and patching are all important considerations when managing your own server. You must take into account the volume of traffic your application will experience when you deploy it to a server. You might need to scale up to accommodate the traffic if your server is running at 100 percent of its capacity

If your server is only being used 10% utilization, you might consider scaling down to save money.

AWS Lambda is a serverless compute solution that allows you to run code without the need for server provisioning or management. You only pay for the compute time you use. This indicates that my own project, which will not receive a lot of traffic, is a great choice for AWS Lambda. This use case is ideal for applications with variable traffic or that can scale to zero.

Most people are familiar with this concept when it comes to deploying functions as a service (FaaS), however in this article we will deploy a whole Spring Boot REST API. According to the AWS Pricing Page, the free tier of AWS Lambda includes one million free requests per month and 400,000 GB-seconds of computing time each month. This means that for the majority of the side projects I'm working on, I can deploy them to AWS Lambda for free.

2. Prerequisites

3. Agenda

In this article, you will build a new Spring Boot 3 application, as well as a CRUD REST API, which you will package and deploy to AWS Lambda.

  • start.spring.io spring boot 3.1.0 maven / java web, webflux

  • Build CRUD REST API post package Post Record PostNotFoundException PostController

  • Blog Posts Loader JsonPlaceholderService

  • Test locally using http client before packaging for production

4. Maven Model

The Maven Archetype is a project template that you can use to create new projects. The AWS Serverless Spring Boot 3 Archetype is a Maven project that you can use to create a new Spring Boot 3 project that includes an AWS Serverless container for Spring Boot 3. This will also create the exact Maven configuration needed. needed to create an AWS Lambda deployment package. If you are using IntelliJ IDEA, you can use the Maven Archetype to generate a new project but you can also use Spring Initializr. aws-serverless-springboot3-archetype

If Maven is already installed, you can use the following command to create a new project: ย 

mvn archetype:generate -DgroupId=my.service -DartifactId=my-service -Dversion=1.0-SNAPSHOT \
       -DarchetypeGroupId=com.amazonaws.serverless.archetypes \
       -DarchetypeArtifactId=aws-serverless-springboot3-archetype \
       -DarchetypeVersion=2.0.0-M1

5. AWS Resources

To deploy your application to AWS Lambda, you must first create the AWS resources listed below.

  • AWS Lambda
  • API Gateway

You can create the resources manually using the AWS Console, or you can use code. In this Article you will use the AWS Console, but I have included some resources if you want to learn more about SAM and CDK.

AWS SAM

SAM stands for Serverless Application Model. It's an open-source framework for creating serverless applications on AWS. It simplifies the definition of AWS resources (infrastructure as code) required to run your application. It also includes a command line interface (CLI) for packaging and deploying your application to AWS.

SAM defines your application using a template file (template.yaml). The AWS resources required to run your application are defined in the template file. You should go over that template file and review it before deploying your application.

mvn clean package sam deploy --guided

AWS CDK

CDK stands for Cloud Development Kit AWS CDK is an open source software development framework that allows you to define the resources of your cloud application using familiar programming languages. Because the AWS CDK allows you to define your infrastructure in standard programming languages, you can write automated unit tests for your infrastructure code in the same way that you do for your application code.

spring-serverless-aws's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.