AWS ApiGateway请求模板直通

时间:2016-09-27 17:28:44

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

我正在使用Lambda - >使用Java的ApiGateway和我需要Stage Variables。

我使用亚马逊提供的默认模板作为集成请求:

##  See http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
##  This template will pass through all parameters including path, querystring, header, stage variables, and context through to the integration endpoint via the body/payload
#set($allParams = $input.params())
{
"body-json" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
    #set($params = $allParams.get($type))
"$type" : {
    #foreach($paramName in $params.keySet())
    "$paramName" : "$util.escapeJavaScript($params.get($paramName))"
        #if($foreach.hasNext),#end
    #end
}
    #if($foreach.hasNext),#end
#end
},
"stage-variables" : {
#foreach($key in $stageVariables.keySet())
"$key" : "$util.escapeJavaScript($stageVariables.get($key))"
    #if($foreach.hasNext),#end
#end
},
"context" : {
    "account-id" : "$context.identity.accountId",
    "api-id" : "$context.apiId",
    "api-key" : "$context.identity.apiKey",
    "authorizer-principal-id" : "$context.authorizer.principalId",
    "caller" : "$context.identity.caller",
    "cognito-authentication-provider" : "$context.identity.cognitoAuthenticationProvider",
    "cognito-authentication-type" : "$context.identity.cognitoAuthenticationType",
    "cognito-identity-id" : "$context.identity.cognitoIdentityId",
    "cognito-identity-pool-id" : "$context.identity.cognitoIdentityPoolId",
    "http-method" : "$context.httpMethod",
    "stage" : "$context.stage",
    "source-ip" : "$context.identity.sourceIp",
    "user" : "$context.identity.user",
    "user-agent" : "$context.identity.userAgent",
    "user-arn" : "$context.identity.userArn",
    "request-id" : "$context.requestId",
    "resource-id" : "$context.resourceId",
    "resource-path" : "$context.resourcePath"
    }
}

我切换到新的Aws SDK(现在包括Jackson JSON Parsing)并使用此类来解析模板数据:

https://github.com/ingenieux/lambada/blob/master/lambada-runtime/src/main/java/io/ingenieux/lambada/runtime/model/PassthroughRequest.java

现在我的问题是,我创建了一个Unittest并让他们解析一个例子。一切都很好。但是当它在AWS中运行时,阶段变量不会被填充。

如果我改变了阶段变量" to" stageVariables"在模板中并调整java类......它正确填充。

为什么它没有使用" - "在属性名称?

由于

1 个答案:

答案 0 :(得分:0)

我无法通过查看您提供的模板和类源来诊断问题。

您是否可以在API上启用CloudWatch日志并运行测试。这应该允许您查看哪些API网关传递给Lambda,这将让我们确定问题是在模板还是Java类中。