1

I have a basic service in Java, for example:

public interface FolderService {
   void deleteFolder(String path);
   void createFolder(String path, String folderName);
   void moveFolder(String oldPath, String newPath);
}

which has multiple implementations. How can I map this service on AWS Lambda and API Gateway ?

I am expecting the API to have the format

POST {some_url}/folderService/createFolder

or

GET {some_url}/folderService/createFolder?path=/home/user&folderName=test

1
  • What I did is manually create the methods and resources in API Gateway for every method and assigned each one a new Lambda function (which reuses the same jar but has a different handler). I am looking for a more automated approach. Commented Jun 9, 2017 at 12:27

1 Answer 1

2

First, design your API mapping each HTTP method to a Java method.

  • DELETE /{path}
  • POST /{path}/{folderName}
  • PUT /{oldPath}?to={newPath} or PUT /{newPath}?from={oldPath}

Second, create the API Gateway Mapping. Each HTTP method has its own mapping. Define a constant value with the name of the method. Ex.

"action" : "deleteFolder"

Create three lambda functions. Each function, in the function handler, reads the "action" attribute and call the correct method.

or

Create one single lambda function that reads the action and calls the respective Java method.

You already have experience with AWS Lambda? The mapping part can be tricky. Feel free to ask for more details.

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

2 Comments

If I create a single lambda function for multiple java methods then I can't handle the input json (it differs on each method call). How can I have a dynamic input/output json schema for a lambda ? Thank you
The mapping is free. So, you can, for instance, define a responseBody attribute that receives your data independently of wich method was performed. Ex: { $inputRoot.responseBody } or { "data": $inputRoot.myResponse } In this case, the Handler has to include a "responseBody" or "myResponse" in the response object that is referred as $ variables in the mapping.

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.