从Java Service到AWS Lambda和AWS Gateway API

时间:2017-06-09 12:23:36

标签: java amazon-web-services aws-lambda aws-api-gateway

我在Java中有一个基本服务,例如:

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

有多个实现。如何在AWS Lambda和API Gateway上映射此服务?

我希望API具有格式

POST {some_url} / folderService / createFolder

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

1 个答案:

答案 0 :(得分: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.