2017-04-18 91 views
0

我有一个简单的AWS Lambda,它从S3存储桶中获取JSON文件并返回文件的内容。最重要的是,我为这个lambda创建了API网关。使用GET方法更新API,使用查询参数,在执行窗格中。当我测试它形成API网关时,所有似乎都正常工作。当我从NodeJS尝试相同的时候,Lambda日志清楚地发现没有任何查询参数被传递。我无言以对如何事情可以从API网关的工作,而不是通过我的NodeJS应用 enter image description hereAWS Lambda函数从API网关调用时没有事件参数

enter image description here

enter image description here

这里是我以前在生成模板部分

## 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" 
    } 
} 

回答

0

代码如果在API网关控制台中测试API可按预期工作,则听起来您可能需要部署API。

请参阅deploying an API上的文档。

0

正如马克提到的,您可以尝试部署。

此外,还有从API网关与λ的集成延迟

我会建议通过嵌套它或以某种方式调用事件在运行时延迟事件调用可能是通过使用承诺,因为nodejs是异步的,您的事件可能会在数据到达之前调用。

此外,您可以通过转到API网关> API>'API-NAME'>仪表板来验证延迟。

相关问题