【发布时间】:2018-05-04 04:04:48
【问题描述】:
我在 AWS 中配置了一个自定义授权器 lambda 函数,用于将 API 配置为具有 POST 资源的另一个 Lambda 函数。
授权方设置为 Request 类型,而不是 Token,因为我没有在 Authorization 标头中使用令牌,而是想要访问正在发布的表单数据。
当我检查我的授权函数的 event 参数的内容时,我看不到任何原始的 POST 请求正文(表单数据)。但是,如果我将资源更改为GET,我会按预期看到queryStringParameters 中的表单数据。
(注意下面当请求为 POST 时,queryStringParameters 始终为空对象)
当使用POST 方法时,是否可以从函数中的请求访问表单数据?
以下是使用 POST 时授权函数的 event 参数将包含的内容的示例:
{
type: 'REQUEST',
methodArn: 'arn:aws:execute-api:us-east-1:********:********/dev/POST/receive',
resource: '/receive',
path: '/sms/receive',
httpMethod: 'POST',
headers: {
Accept: '*/*',
'CloudFront-Viewer-Country': 'US',
'CloudFront-Forwarded-Proto': 'https',
'CloudFront-Is-Tablet-Viewer': 'false',
'CloudFront-Is-Mobile-Viewer': 'false',
'User-Agent': 'TwilioProxy/1.1',
'X-Forwarded-Proto': 'https',
'CloudFront-Is-SmartTV-Viewer': 'false',
Host: 'api.myredactedcompany.io',
'X-Forwarded-Port': '443',
'X-Amzn-Trace-Id': 'Root=**************',
Via: '1.1 ***************.cloudfront.net (CloudFront)',
'Cache-Control': 'max-age=259200',
'X-Twilio-Signature': '***************************',
'X-Amz-Cf-Id': '****************************',
'X-Forwarded-For': '[redacted IP addresses]',
'Content-Length': '492',
'CloudFront-Is-Desktop-Viewer': 'true',
'Content-Type': 'application/x-www-form-urlencoded'
},
queryStringParameters: {},
pathParameters: {},
stageVariables: {},
requestContext: {
path: '/sms/receive',
accountId: '************',
resourceId: '*****',
stage: 'dev',
requestId: '5458adda-ce2c-11e7-ba08-b7e69bc7c01c',
identity: {
cognitoIdentityPoolId: null,
accountId: null,
cognitoIdentityId: null,
caller: null,
apiKey: '',
sourceIp: '[redacted IP]',
accessKey: null,
cognitoAuthenticationType: null,
cognitoAuthenticationProvider: null,
userArn: null,
userAgent: 'TwilioProxy/1.1',
user: null
},
resourcePath: '/receive',
httpMethod: 'POST',
apiId: '*******'
}
}
【问题讨论】:
标签: amazon-web-services lambda aws-lambda