How to create serverless function with spring cloud function, deploy into AWS Lambda and expose rest endpoint using AWS API Gateway | Learn Java Skills

Imran Shaikh
0

Now a days, serverless functions are gaining much more popularity because developers don't want to spend valuable time configuring the server themselves or maintaining the operating system patch update manually.


There are three main advantages to using the serverless function (Spring Cloud Function).


  • No efforts were required for us to setup servers, like software installation, before deploying them into production.

  • Maintenance of the server, like software patch updates, is eliminated.

  • Serverless functions are auto-scalable by nature if you deploy them in the cloud, such as AWS, GCP, or Azure.

In this tutorial, you can expect to learn how to build your first serverless function using the Spring cloud function and deploy it into the cloud.


There are many cloud providers that offer serverless function deployment, such as Google (GCP), Azure, or Amazon AWS. In this tutorial, you can expect the end-to-end development of the spring cloud function and deployment into the AWS lambda.


We are not only deploying our cloud function into AWS, but we will also make sure that it is accessible via the Rest endpoint by configuring the AWS API Gateway with our AWS lambda.


toc
SERVERLESS FUNCTION WITH SPRING CLOUD FUNCTION | AWS LAMBDA | AWS API GATEWAY thumbnail image

This tutorial is divided into four sections, as follows:



  • First, we will create a Spring cloud function and run it locally.

  • Second, in Spring Boot version 3, we are going to build a Spring Cloud function that should be compatible with AWS lambda function deployment.

  • We will learn how to trigger the AWS lambda function with the AWS API Gateway endpoint.

  • Fourth, we'll look at how we can configure this spring cloud function in Spring Boot version 2, as well as what adjustments we need to make to the handler setting in the AWS lambda function when compared to Spring Boot version 3.

Spring Cloud Function in local


In this section we will learn how to develope a spring cloud function and run function locally.


Maven Dependency

Thre are two main dependencies need to be added and they are as followed

  • spring-cloud-starter-function-web
  • spring-cloud-dependencies

  <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>3.1.3</version>
      <relativePath/> <!-- lookup parent from repository -->
   </parent>
   <groupId>in.learnjavaskills</groupId>
   <artifactId>spring-cloud-function-local</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <name>spring-cloud-function-local</name>
   <description>Demo project for Spring Boot</description>
   <properties>
      <java.version>17</java.version>
      <spring-cloud.version>2022.0.4</spring-cloud.version>
   </properties>
   <dependencies>
      <!-- Spring Cloud Function  -->
      <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-function-web</artifactId>
      </dependency>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
         <scope>test</scope>
      </dependency>
   </dependencies>
   <dependencyManagement>
      <dependencies>
         <!-- spring cloud dependencies -->
         <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
         </dependency>
      </dependencies>
   </dependencyManagement>

   <build>
      <plugins>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
      </plugins>
   </build>

 </project>

The Spring cloud function along with the functional interface introduction.

Only one rest endpoint can be expose by using the Spring cloud function. You can configure many functional interfaces with the bean in your application, but only one should be accessible to the end user at a time.


The Spring Cloud function exposes the rest endpoint using three frequently utilized functional interfaces. This functional interface, which was introduced in Java 8 as part of the java.util.function package, is as follows:


Function Interface

The Function interface has two arguments that we must declare when utilizing it: T and R. The T parameter indicates the function's request type, while the R parameter determines the function's return type.


 @FunctionalInterface
 public interface Function<T, R> {
 }

The abstract method in the Function interface that we must override when using the Function interface is the apply() method.


The apply() method expects to return the result with the same return data type that we defined when we declared the generic type in the function interface. It accepts one argument of the data type that we specified when we created the function interface.


R apply(T t);(code-box)

Consumer Interface

The consumer interface, as the name suggests, is used to consume data and does not return any data. The only generic available in the user interface is T.


 @FunctionalInterface
 public interface Consumer<T> {
 } 

The consumer interface has one abstract method, accept(). The accept method takes one parameter of type specified as the consumer interface's generic type.


void accept(T t);(code-box)

Supplier Interface

When we wish to get some data without providing any arguments as input, we utilize the supplier interface. When using the supplier interface, we only need to decide on one generic type, T, which specifies the function's return type.


 @FunctionalInterface
 public interface Supplier<T> {
 } 

The Supplier interface has one abstruct function, get(). The get() method must return data of the same generic T type that has been defined in the Suppier interface's generic type.


T get();(code-box)

Developing a Rest API using the Spring cloud function

I'm developing an API that will be responsible for counting the amount of words in a given String. I've created one  java record (Response) to transmit the API response. First, let's make a Response record.

If you are using Java 8 or Java 11, you may substitute POJO for the java record.


 package in.learnjavaskills.springcloudfunctionlocal;

 public record Response(int status, String message, Long wordCount)
 {}

Create a @Bean to expose the Rest Endpoint.

After we've finished developing the response record file, we can start working on a bean to expose the rest enpoint.


 package in.learnjavaskills.springcloudfunctionlocal;

 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.Bean;

 import java.util.Objects;
 import java.util.function.Function;

 @SpringBootApplication
 public class SpringCloudFunctionLocalApplication
 {

   public static void main(String[] args)
   {
     SpringApplication.run(SpringCloudFunctionLocalApplication.class, args);
   }

   @Bean(name = "find-word-count")
   public Function<String, Response> findWordCount()
   {
     return request ->
     {
       if (Objects.nonNull(request) && Objects.nonNull(request) && !request.isEmpty())
       {
         if (request.contains(" "))
         {
           long wordCount = request.split(" ").length;
           return new Response(200, "success", wordCount);
         }
       }
       return new Response(409, "fail", 0L);
     };
   }
 }
 

Testing rest enpoind

Let's put it to the test now. Use curl to execute the above enpoint.


curl -H "Content-Type: application/json" localhost:8080/find-word-count -d "Learn Java Skills"(code-box)

The output is shown below.


{"status":200,"message":"success","wordCount":3} (code-box)

How do you write a Spring Cloud function in Spring Boot 3 and publish it to AWS Lambda?


architecture diagram

Till, Now we are able to develop the spring cloud function, which we can also run on our local machine. But this function is not yet ready to deploy into AWS because we do need to update the dependencies and code to make it compatible with the AWS lambda function.


Let's develop a serverless function with the Spring cloud function and deploy it to AWS Lambda. This time, we'll write a method that will reverse the given string.


AWS Lambda Dependencies


The libraries listed below are necessary in our project to develop the serverless function (Spring Cloud Function) and deploy it to AWS Lambda.


  • spring-cloud-function-adapter-aws
  • aws-lambda-java-events
  • aws-lambda-java-core
  • spring-cloud-dependencies

pom.xml

 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.1.3</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  
  <groupId>in.learnjavaskills</groupId>
  <artifactId>spring-cloud-function-aws-lambda</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>spring-cloud-function-aws-lambda</name>
  <description>Demo project for Spring Boot</description>
  
  <properties>
    <java.version>17</java.version>
    <spring-cloud.version>2022.0.4</spring-cloud.version>
    <aws-lambda-events.version>3.9.0</aws-lambda-events.version>
    <aws-lambda-java-core-version>1.1.0</aws-lambda-java-core-version>
  </properties>
  
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-function-adapter-aws</artifactId>
    </dependency>

    <dependency>
      <groupId>com.amazonaws</groupId>
      <artifactId>aws-lambda-java-events</artifactId>
      <version>${aws-lambda-events.version}</version>
    </dependency>

    <dependency>
      <groupId>com.amazonaws</groupId>
      <artifactId>aws-lambda-java-core</artifactId>
      <version>${aws-lambda-java-core-version}</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>${spring-cloud.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

Thin layout plugin

Before we can deploy our spring cloud function into the AWS lambda function, we must first build a thin jar of our project.


Why do we require a thin jar?


Spring Boot applications come with lots of libraries, and AWS Lambda provides a layer where we can upload our common library, and later, when establishing an AWS function, we can add those layers to our function.


We only provide our source code by producing a thin jar. We will additionally generate a bundled jar containing all of the libraries required to run our AWS Lambda layer.


Add the spring-boot-thin-layout and maven-shade-plugin plugins to the build tag to generate the thin and bundle jars.


 <build>
    <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <dependencies>
          <!-- building thin jar for deploying into the AWS lambda, because dependencies
            are required at the runtime in the AWS lambda -->
          <dependency>
            <groupId>org.springframework.boot.experimental</groupId>
            <artifactId>spring-boot-thin-layout</artifactId>
            <version>${wrapper.version}</version>
          </dependency>
        </dependencies>
        <configuration>
          <excludes>
            <exclude>
              <groupId>org.projectlombok</groupId>
              <artifactId>lombok</artifactId>
            </exclude>
          </excludes>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <configuration>
          <createDependencyReducedPom>false</createDependencyReducedPom>
          <shadedArtifactAttached>true</shadedArtifactAttached>
          <shadedClassifierName>aws</shadedClassifierName>
        </configuration>
      </plugin>

    </plugins>

  </build>

Write a Spring Cloud function to reverse a given string.

We'll start by writing a function and annotating it with the @Bean annotation. As a result, it will be triggered when we run the AWS lambda code.


 package in.learnjavaskills.springcloudfunctionawslambda;

 import in.learnjavaskills.springcloudfunctionawslambda.dto.GatewayRequest;
 import in.learnjavaskills.springcloudfunctionawslambda.dto.GatewayResponse;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.Bean;

 import java.util.Objects;
 import java.util.function.Function;

 @SpringBootApplication
 public class SpringCloudFunctionAwsLambdaApplication 
 {
   public static void main(String[] args) 
   {
     SpringApplication.run(SpringCloudFunctionAwsLambdaApplication.class, args);
   }

   @Bean
   public Function<GatewayRequest, GatewayResponse> reverseTextFunction()
   {
     return gatewayRequest -> {
       if (Objects.nonNull(gatewayRequest) && Objects.nonNull(gatewayRequest.getText()))
       {
         String reverseText = new StringBuffer(gatewayRequest.getText()).reverse().toString();
         return new GatewayResponse(200, reverseText, "Success");
       }
       return new GatewayResponse(409, null, "fail");
     };
   }
 }

As you can see from the code above, I used GatewayRequest and GatewayResponse to accept the user request and return the result. In our code, let us create both POJOs and record.


 public class GatewayRequest
 {
   private String text;

   public String getText()
   {
     return text;
   }
   // Getter and Setter, toString, equal and hashcode methods
 }

 package in.learnjavaskills.springcloudfunctionawslambda.dto;

 public record GatewayResponse(int status, String reverseText, String message)
 {} 

For the GatewayResponse, I have use a record. You can utilize Java Pojo in your Spring Cloud function if you are running Java 8 or Java 11.


Create packages for AWS Lambda deployment.

Let's create a package by running the following command:


mvn clean install (code-box)

After successfully building the package, you should see the following jar in the targer folder:

target folder structure with jar

We are only interested in spring-cloud-function-aws-lambda-0.0.1-SNAPSHOT.jar and spring-cloud-function-aws-lambda-0.0.1-SNAPSHOT-aws.jar for the time being. Which will be used in the AWS Lambda function and AWS Lambda Layer.


Set up the AWS Lambda Function with the Spring Cloud Function.


You must have an active AWS account before attempting this activity. If you don't already have an AWS account, you may sign up for a 12-month free tier account from here.


Log into your AWS Lambda account, select the nearest region, and then search for AWS Lambda in the search field, as seen in the image below.


I'm working in the Mumbai region for this activity.


search-aws-lambda-from-aws-console

After successfully completing the lambda search, you will be directed to the AWS lambda function's home page, as seen below.


To create a new lambda function, click the create a function button.

aws-lambda-home-screen

You'll now be asked to choose a function creation option. We must select the author from scratch option from the screen given below because we will be deploying our own Spring Cloud service.

create-aws-lambda-function-screen

Let's fill out the Basic Information box with the lambda function name and runtime version.


I named it spring-cloud-function-with-spring-boot-version-3 because I used Spring Boot version 3 instead of Spring Boot version 2 since Spring Boot version 2 has various setups, which I'll illustrate later.


Because I use open JDK 17 in order to build the Spring cloud function on my machine, the runtime version is Java 17. You can change the Java version to match your JDK version.


aws-lambda-basic-information-screen

Once you've completed all of the steps, you may use the create function button to create your first AWS lambda function.

create-function-image

When you use the create function button, your first AWS lambda has been successfully created. You can confirm this by looking at the screen below.

aws-lambda-function-created-succesfully-image

Are all of our AWS Lambda configurations complete?


Surprisingly, we have yet to deploy our spring cloud function code into the AWS Lambda function.


Remember that we made two jars. Spring-cloud-function-aws-lambda-0.0.1-SNAPSHOT.jar was one, and spring-cloud-function-aws-lambda-0.0.1-SNAPSHOT-aws.jar was the other.


It's time to deploy one of those jars into the lambda function. The spring-cloud-function-aws-lambda-0.0.1-SNAPSHOT.jar package jar is our thin jar, which we are now putting into our AWS Lambda function.


Scroll down to the code portion of the AWS Lambda function, where you will find the upload from button, as seen in the image below. To deploy spring-cloud-function-aws-lambda-0.0.1-SNAPSHOT.jar, click the upload from button.

uploading-artifact-in-aws-lambda-function-screen

In the aws lambda function, you have two options for uploading your artifact or jar. You can either zip your artifact or jar before uploading it to the lambda function, or you can immediately upload your jar.


Second, you can upload your artifact or jar into the AWS S3 bucket and then selecting it into the AWS lambda function to upload it.


In our example, we are uploading our jar directly into the AWS Lambda function by using the.zip or.jar option.

two-option-in-uploading-artifact-screen

An upload box will appear, allowing you to select your jar, which will be deployed into the AWS Lambda function. Click the upload button, navigate to the jar in your file explorer, and then click the save button.

select-jar-file-from-file-explorer

Congratulation, Your thin jar was successfully uploaded to the AWS lambda function. You may validate this by looking at the screen below on your AWS Lambda Function page:

success-scrren-of-uploading-file

Adding a layer to the AWS layer or installing a dependent Spring cloud function library


Is our Aws Lambda function suitable for testing?


Unfortunately, it is not. We still need to deploy our spring cloud function library into the AWS layer and connect it to our AWS lambda function. Till now we have only deployed our code into the AWS lambda function.


Let's make a layer and insert our jar into it.


Hit the three horizontal lines in the top left sidebar to expand the side bar menu, and then select the layer as shown in the screenshot below.

lambda-side-bar-to-choose-layer

You'll now be taken to the layer's main screen. To begin generating a layer, click the create layer button, as seen below.

create-layer-button

To upload the spring-cloud-function-aws-lambda-0.0.1-SNAPSHOT-aws.jar into the layer, zip the artifact into the java/lib folder.


Complete the layer configuration form. You can enter any name in the name text box, however for this example, I'm using spring-cloud-function-library.


Even if it is optional, don't forget to fill out the description. It will assist you in determining which libraries are included in this layer.


Upload your zip file, choose a compatible runtime (for us, Java 17), and click the Create button.


The AWS Lambda function allows us to upload a jar with a maximum size of 50 MB, and if the jar size is larger than or equivalent to 10 MB, we should use AWS S3.(alert-success)

layer-configuration-screen
runtime-version-chosse-for-layer

Hurray! We have finished developing a layer in AWS lambda. Look at the screen below to confirm your layer creation.

Layer-Created-Successfully

Attached layer into the AWS Lambda Function

It's finally time to connect this layer to the AWS lambda function.


Open your lambda function, then scroll down until you find the layers section. To add a layer to this AWS lambda function, locate the add layer button.

add layer button screen on lambda function

The Add Layer dialog box will display. Select the Custom Layer radio button under the Choose Layer section, and then select the spring-cloud-function-library that we recently generated under the Customer Layer drop-down.


Don't forget to select the layer's version. Because this is the first time we are deploying it, it will be version 1.

add layer dialog box 1
add layer dialog box 2

The layer will be successfully added once you press the add button. You can see if it's been added or not by looking at the layer section.

layer-added screen
The layer's maximum zip file size is 250 MB, and you can add up to 5 layers in one AWS lambda function.(alert-passed)

Configure the handler in the AWS lambda function


To use the aws lambda function, we must first configure the request handler.


The org.springframework.cloud.function.adapter.aws.FunctionInvoker is one of the generic request handlers that is implemented in the AWS RequestStreamHandler.


Navigate to the runtime settings and click the edit button, as seen in the figure below.

runtime-setting

Change the name of the handler to org.springframework.cloud.function.adapter.aws.FunctionInvoker as shown in the figure below, and then click the save button.

handler-setting-update

AWS Lambda Function Testing


Hurray! We have completed all of the prerequisites required to run the AWs lambda function. However, before connecting this AWS lambda function to the API Gateway to build a rest API, we must first ensure that the function is functioning properly.


To quickly validate the AWS lambda function, let's proceed to the test part.


The AWS lambda function offers us the ability to create an event to test our lambda function. Let's create an event with the name verify reverse string under the event JSON and send the following payload:

event creation
payload screen

After inserting the payload, click the save button, followed by the test button.


The AWS Lambda function limits us to completing the execution of the entire function within 15 minutes, which implies we can only perform a function execution within 15 minutes.(alert-warning)

When you press the test button, the AWS lambda will respond as seen in the figure below.

testing the lambda function

You may debug your request trail by checking in the function's log, just like the response of the aws lambda.


Let's trigger our lambda function by creating the rest api using the API gateway


There are various ways of launching an AWS Lambda function, but for the purposes of this demonstration, we'll use the AWS API Gateway to do it.


The publishing, monitoring, and security of restful webservices are all handled by the fully managed Amazon API Gateway service.


The AWS API gateway serves as the entrance point for your apps before connecting to the business logic.


Are you delighted to use the API gateway to launch your first AWS lambda? If so, expose the rest endpoint to call the lambda function.


Navigate to your AWS lambda function and look for the add trigger button, as seen in the screenshot below.

add-trigger-button

The Add Trigger Configuration window will now appear. Select the API gateway from the Trigger Configuration drop-down menu.

add-trigger-configuration-window-api-gateway-select

Select the new API from the intent radio button, and ensure that the HTTP API type is selected in the API time section.


There are two ways to construct a restful webservice in the AWS API gateway, and they are as follows:
HTTP APIs: HTTP APIs have been designed with fewer functionalities and are less expensive than Rest APIs.
Rest APIs: In comparison to HTTP APIs, Rest APIs provide greater functionalities. If you require API keys, per-client throttling, request validation, AWS WAF integration, or private API endpoints, use REST APIs.(alert-success)

new-api-type-select

Choose open from the security drop-down because we're making this API open, which means we won't require API authentication to use it, and then click the add button to configure the API gateway trigger into the AWS lambda function.

security choose section of the api gateway

Use the API endpoint provided by the API Gateway to test the AWS lambda function.

After clicking the add button, you can discover the API gateway that has been configured in the trigger section of the configuration.


You will also be provided with the API endpoint for executing the AWS lambda function.

API enpoint from the configuration

Let's put this AWS lambda function to the test now, utilizing the API endpoint supplied by the API Gateway.


Copy and paste the API endpoint into Postman, then submit the json payload under the body, and we want the content to be reversed from the response.

api testing

As we can see from the response, we were able to retrieve the expected response from the AWS lambda function. It represents that we were able to successfully configure the AWS API gateway for our AWS lambda function.


How to build a spring cloud function in Spring Boot 2 and deliver it to AWS Lambda.


We've seen how to establish a spring cloud function in Spring Boot version 3, however there are some minor code changes in Spring Boot version 2 that we'll go over right now.


Instead of generating a bean in Spring Boot version 2, we must first develop a handler class that will be responsible for extending the SpringBootRequestHandler class.


 package in.learnjavaskills.springcloudfunctionawslambda.handler;

 import in.learnjavaskills.springcloudfunctionawslambda.dto.GatewayRequest;
 import in.learnjavaskills.springcloudfunctionawslambda.dto.GatewayResponse;

 import org.springframework.cloud.function.adapter.aws.SpringBootRequestHandler;

 public class RequestHandler extends SpringBootRequestHandler<GatewayRequest, GatewayResponse>
 {} 

After you've successfully constructed a handler class, let's make one class that implements the Functiona interface. In this, we will override the apply method, which is the functional interface's abstract method, and then add code to reverse and string.


 package in.learnjavaskills.springcloudfunctionawslambda.handler;

 import in.learnjavaskills.springcloudfunctionawslambda.dto.GatewayRequest;
 import in.learnjavaskills.springcloudfunctionawslambda.dto.GatewayResponse;
 import org.springframework.stereotype.Service;

 import java.util.Objects;
 import java.util.function.Function;

 @Service
 public class RequestHandlerService implements Function<GatewayRequest, GatewayResponse>
 {

   @Override
   public GatewayResponse apply(GatewayRequest gatewayRequest)
   {
     if (Objects.nonNull(gatewayRequest) && Objects.nonNull(gatewayRequest.getText()))
     {
       String reverseText = new StringBuffer(gatewayRequest.getText()).reverse().toString();
       return new GatewayResponse(200, reverseText, "Success");
     }
     return new GatewayResponse(409, null, "fail");
   }
 }

That's all the code changes we need to make in Spring Boot version 2 versus Spring Boot 3. For Spring Boot Version 2, all dependencies will be the same.


Simply use the Spring Cloud version that is compatible with Spring Boot version 2.


Changes to the AWS lambda handler for Spring Boot version 2

The deployment to the AWS lambda function is identical to what we described earlier in this guide for Spring Boot version 3.


However, because we changed the code, we must configure the class's handler.


We created a handler called RequestHandler class. As a result, we have to provide the absolute path of a package of this class in the AWS Lambda Function's handler configuration.


in.learnjavaskills.springcloudfunctionawslambda.handler.RequestHandler(code-box)

I've already deployed the Spring Boot version 2 (Spring Cloud function), and you may edit the handler setting by navigating to the function's runtime settings, as seen in the image below.


spring boot version 2 spring cloud function aws lambda dashboad
aws handler setting

Conclussion


In this course, we learned how to create a spring cloud function and run it on our local system. In Spring Boot Versions 2 and 3, we learn how to develop a spring cloud function and deploy it to AWS Lambda.


We not only built the spring cloud function, but we also saw how to deploy it into the AWS lambda function. We'll look at the layer in the AWS lambda function and how to use it.


We also built a Rest API by triggering our AWS lambda function through the API gateway.

Once you've finished your lab exercise, remember to delete your AWS lambda function, layer, and API Gateway.(alert-error)

Keep learning and keep growing.

Post a Comment

0 Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top