1

Is it possible to create a REST API with lambda backend using AWS Java SDK?

I have been able to create HTTP API using software.amazon.awssdk.services.apigatewayv2.ApiGatewayV2Client with a lambda backend, but havent found the right sdk functions to do the same for REST APIs. I want to create REST APIs as it supports api-keys.

I understand that we can use Clouformation templates/Serverless framework etc to achieve my objective.

However, in this instance, I am working out a devops product that can create AWS API endpoints and am using a Java based framework(springboot) to expose APIs to do so. The Java APIs is intended create an AWS REST API with resources, authorizers, apikeys etc while the backend logic is left to the implementation team.

1
  • 1
    Typically you would use a solution such as CloudFormation, CDK, or Terraform to build and deploy your infrastructure (the API endpoint and backing Lambda function). You would not typically use Java to do this, though there is no reason that you could not create the individual AWS resources using the AWS Java (or any supported language) SDK. Commented Jul 30, 2023 at 20:49

1 Answer 1

3

To build a Rest API that lets a client app (for example, a React APP) invoke Lambda functions via API Gateway, you should look at using the AWS CDK to create API Gateway endpoints.

Then you can use the AWS SDK for Java to implement Lambda functions that perform various AWS Service operations. For example, save data in an Amazon DynamoDB table.

Because there is a lot of detail involved in how to do this use case, this is a detailed end to end AWS App example. Consider this architecture illustration:

enter image description here

In this use case, the API Gateway REST API was created via the AWS CDK and the AWS SDK for Java v2 API was used to invoke AWS Service opertions and were implemented as Lambda functions.

To see the complete details, including the CDK Script (note that the link to the CDK script is located near end of the doc), see:

https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/usecases/pam_source_files

If you spend time reading this and going through all the code, you will gain a much deeper undertanding how all of these pieces fit together. The final app looks like:

First it requires you to log in which authenticates with Cognito:

enter image description here

Then it invokes various AWS Service operations and displays a tag count of objects located in an S3 bucket:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.