Amazon web services 从API网关调用AWS Lambda函数时没有事件参数
我有一个简单的AWS Lambda,它从S3存储桶中获取一个JSON文件并返回该文件的内容。在此基础上,我为这个lambda创建了API网关。在执行窗格中使用GET方法和查询参数更新了API。当我从API网关测试它时,一切似乎都正常。当我在NodeJS中尝试同样的方法时,Lambda日志清楚地表明似乎没有传递任何查询参数。我不知道如何从API网关而不是通过我的NodeJS应用程序工作 下面是我在生成模板部分使用的代码Amazon web services 从API网关调用AWS Lambda函数时没有事件参数,amazon-web-services,aws-lambda,aws-api-gateway,Amazon Web Services,Aws Lambda,Aws Api Gateway,我有一个简单的AWS Lambda,它从S3存储桶中获取一个JSON文件并返回该文件的内容。在此基础上,我为这个lambda创建了API网关。在执行窗格中使用GET方法和查询参数更新了API。当我从API网关测试它时,一切似乎都正常。当我在NodeJS中尝试同样的方法时,Lambda日志清楚地表明似乎没有传递任何查询参数。我不知道如何从API网关而不是通过我的NodeJS应用程序工作 下面是我在生成模板部分使用的代码 ## See http://docs.aws.amazon.com
## 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"
}
}
如果在API网关控制台中测试API按预期工作,那么听起来您可能需要部署API
请参阅上的文档。如Mark所述,您可以尝试部署 此外,从API网关到Lambda还有一个集成延迟 我建议通过嵌套来调用事件,或者通过使用承诺来延迟运行时的事件调用,因为nodej是异步的,所以您的事件可能会在数据到达之前被调用 此外,您还可以通过转到API网关>API>'API-NAME'>仪表板来验证延迟