Let's Go Serverless

What does it mean to go serverless?

Serverless computing is a cloud computing execution model in which a cloud provider runs the server, and dynamically manages the allocation of machine resources. Cloud computing can be a bit overwhelming when looking for the right service to use, like AWS ( Amazon Web Services) which offers a lot of services for different purposes. You can see the services they offer HERE.

Now, let’s talk about the juicy part. ‘AWS LAMBDA’. This is one of Amazons Web Services, It is a serverless compute that runs code in response to events and automatically manages the computing resources required by that code.

At Flutterwave, we use AWS Lambda and here are the reasons why:

  1. Microservice Architecture: This helps us ensure minimal downtime using this service, and if downtime occurs it doesn’t affect other services.
  2. Cost: We provide our customers with unbeatable pricing and this service also allows us to watch our costs.
  3. Scalability: We are expanding by the day and the AWS Lambda gives us the ability to scale our products to handle as many customers.

So let’s begin…

We will be consuming a free API from reqresusing JAVA, our Lambda function will GET a list of users from an endpoint.

First is our entry point, see code below:

Our service class:

Things to note on our Config file, we will define our API_URL variable with an environment variable, “System.getenv(“API_URL”)”, this is because we will set the value on our lambda function console, See config below:

package com.flutterwave.reqres.config;
public class ReqresConfig {
 public static String API_URL = System.getenv(“API_URL”);

Build your project to a .jar file.

Next step is uploading to AWS, open your lambda consoleand click on create function button, 

select “Author from scratch” and fill in the details, our Function Name is reqres, select Java 8 as runtime, I already have a role created, so I will choose an existing role and enter the role name, you can do the same if you have a role existing or create a role, then click create function.

Voila, our function is created,

Next, we will upload our .jar file, click on the dropdown and you will see two options, we will pick “upload a.zip or .jar file”, the “S3” option is for another day *winks*

We will also define our API_URL variable on the environment variable section and save, see image below:

After changes have been saved, click on “test” and you will be shown a page to model your request, we will leave ours as it is and name it “test”, see image below:

Then click on test again and voila, you should get a response like the one below:

And we have a working lambda function, there is a lot more left to learn, including logging, but I think this will get you started.

Thanks for reading.


More amazing articles for you