Amazon web services 是否向Lambda发送了AWS网关事件的任何官方文件?
我一直在搜索从集成(如AWS API网关)发送到AWS Lambda的数据类型的某种官方文档。我在API网关文档中找到了一些“示例”,如和。创建一个Lambda,将输入事件作为输出进行回显并检查输出也相对容易。例如(将REST类型API与Amazon web services 是否向Lambda发送了AWS网关事件的任何官方文件?,amazon-web-services,aws-lambda,aws-api-gateway,documentation,Amazon Web Services,Aws Lambda,Aws Api Gateway,Documentation,我一直在搜索从集成(如AWS API网关)发送到AWS Lambda的数据类型的某种官方文档。我在API网关文档中找到了一些“示例”,如和。创建一个Lambda,将输入事件作为输出进行回显并检查输出也相对容易。例如(将REST类型API与LAMBDA_PROXYintegration一起使用),您会得到如下结果: { "resource": "/another/{parameter}", "path": "/another/some-parameter", "httpMe
LAMBDA_PROXY
integration一起使用),您会得到如下结果:
{
"resource": "/another/{parameter}",
"path": "/another/some-parameter",
"httpMethod": "GET",
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
...
},
"multiValueHeaders": {
"Accept": [
"*/*"
],
"Accept-Encoding": [
"gzip, deflate, br"
],
...
},
"queryStringParameters": null,
"multiValueQueryStringParameters": null,
"pathParameters": {
"parameter": "some-parameter"
},
"stageVariables": null,
"requestContext": {
"resourceId": "some-id",
"resourcePath": "/another/{parameter}",
"httpMethod": "GET",
...
},
"body": null,
"isBase64Encoded": false
}
但这并没有告诉我,我总是可以,或者只是有时候,期望在有效载荷中的字段是什么,或者字段的类型是什么
我对字段的键入最接近的是来自明确键入的项目
关于API网关和其他AWS服务集成的Lambda事件有效载荷的结构和类型,我可以找到更详细、或者更一般的官方来源吗?到目前为止,这是我最接近的答案。如果有人有更详细的(或一般的)信息,我很乐意接受。在这本书中,你可以读到(我的重点): 运行时将三个参数传递给处理程序方法。第一 参数是事件对象,它包含来自 调用者。调用程序以JSON格式传递此信息 字符串,运行时将其转换为对象。 当AWS服务调用您的函数时,事件结构会发生变化 按服务分类。 在lambda文档中的“”下,我们只能找到问题中给出的示例。相反,我们可以查看相关服务的文档,例如。对于API网关,在“使用[HTTP/REST]API”下,您将找到和类型API的事件字段的描述 尽管如此,所提供的文档仍然仅将所描述的有效载荷结构称为“示例”。它只提供字段的名称和一些基本结构。必须从示例中推断数据类型,请参见下面的代码段 对于您可能希望与Lambda集成的其他服务,情况似乎类似,如:
看起来你已经解决了。是的,sorta,我不能说我对结果感到兴奋,但我想这就是事实。AWS可以对他们的文档做一些改进:)
{
version: '2.0',
routeKey: '$default',
rawPath: '/my/path',
rawQueryString: 'parameter1=value1¶meter1=value2¶meter2=value',
cookies: [ 'cookie1', 'cookie2' ],
headers: {
'Header1': 'value1',
'Header2': 'value2'
},
queryStringParameters: { parameter1: 'value1,value2', parameter2: 'value' },
requestContext: {
accountId: '123456789012',
apiId: 'api-id',
authorizer: { jwt: {
claims: {'claim1': 'value1', 'claim2': 'value2'},
scopes: ['scope1', 'scope2']
}
},
domainName: 'id.execute-api.us-east-1.amazonaws.com',
domainPrefix: 'id',
http: {
method: 'POST',
path: '/my/path',
protocol: 'HTTP/1.1',
sourceIp: 'IP',
userAgent: 'agent'
},
requestId: 'id',
routeKey: '$default',
stage: '$default',
time: '12/Mar/2020:19:03:58 +0000',
timeEpoch: 1583348638390
},
body: 'Hello from Lambda',
pathParameters: {'parameter1': 'value1'},
isBase64Encoded: false,
stageVariables: {'stageVariable1': 'value1', 'stageVariable2': 'value2'}
}
{
"openapi": "3.0.0",
"info": {
"version": "2016-09-12T17:50:37Z",
"title": "ProxyIntegrationWithLambda"
},
"paths": {
"/{proxy+}": {
"x-amazon-apigateway-any-method": {
"parameters": [
{
"name": "proxy",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {},
"x-amazon-apigateway-integration": {
"responses": {
"default": {
"statusCode": "200"
}
},
"uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789012:function:SimpleLambda4ProxyResource/invocations",
"passthroughBehavior": "when_no_match",
"httpMethod": "POST",
"cacheNamespace": "roq9wj",
"cacheKeyParameters": [
"method.request.path.proxy"
],
"type": "aws_proxy"
}
}
}
},
"servers": [
{
"url": "https://gy415nuibc.execute-api.us-east-1.amazonaws.com/{basePath}",
"variables": {
"basePath": {
"default": "/testStage"
}
}
}
]
}