1
我定義我的AWS::ApiGateway::Method
這樣AWS LAMBDA越來越空值作爲查詢字符串
GetOrdersMethod:
Type: "AWS::ApiGateway::Method"
Properties:
ApiKeyRequired: true
AuthorizationType: "AWS_IAM"
HttpMethod: "GET"
RequestParameters:
method.request.querystring.orderId: false
ResourceId:
Ref: "GetOrdersPathResource"
RestApiId:
Ref: "GetOrders"
Integration:
Type: "AWS_PROXY"
IntegrationHttpMethod: "POST"
RequestTemplates:
application/json: !Join ["", ["{","\"orderId\": \"$input.params('orderId')\"","}"]]
Uri: !Join ["", ["arn:aws:apigateway:", !Ref "AWS::Region", ":lambda:path/2015-03-31/functions/",!GetAtt GetProgramsLambdaFunction.Arn, "/invocations"]]
我處理這樣定義
public class ProgramHandler implements RequestHandler<Request, String>{
private LambdaLogger logger;
@Override
public String handleRequest(Request request, Context context) {
logger = context.getLogger();
logger.log("FROM LOGGER: ======= LAMBDA INVOKED ======");
logger.log("Input value: " +request.getOrderId());
System.out.println("======= LAMBDA INVOKED ======");
System.out.println("Input value: " +request.getMarketplaceId());
return "Lambda Invoked successfully";
}
}
而且請求是一個簡單的Java POJO與orderId
爲只有有必要的字段和SETTERS
當我測試API網關時,我看到在我的lambda日誌中,訂單ID爲空。但是,我看到它傳遞的日誌上查詢字符串中...這裏是
Tue Apr 25 21:57:31 UTC 2017 : Endpoint request body after transformations: {"resource":"/xxxx","path":"/xxxx","httpMethod":"GET","headers":null,"queryStringParameters":{"orderId":"32"},"pathParameters":null,"stageVariables":null,"requestContext":{"accountId":"xxxxxxx","resourceId":"xxxxx","stage":"test-invoke-stage", ... }
爲什麼我在我的handler
越來越空orderId
?
那麼我怎麼會得到它在我的基於Java的lambda? –
哦,我猜我必須讀取這些輸入流。讓我試試看 –