Javascript 2018年如何访问AWS Lambda中的标题

Javascript 2018年如何访问AWS Lambda中的标题,javascript,node.js,amazon-web-services,aws-lambda,Javascript,Node.js,Amazon Web Services,Aws Lambda,是的,我知道这是一个重复,但是自从提供并设计了映射模板解决方案以来,情况发生了变化。使用代理集成(AWS推荐的方法),无法访问模板。那么,现在如何获得标题呢 我尝试过将对象模型用于以下内容: event.headers event.headers["X-Requested-With"] var headerItem = "x-requested-with" event.headers.headerItem 等等,似乎什么都没有定义 据Cloudwatch称,此次活动是: { "res

是的,我知道这是一个重复,但是自从提供并设计了映射模板解决方案以来,情况发生了变化。使用代理集成(AWS推荐的方法),无法访问模板。那么,现在如何获得标题呢

我尝试过将对象模型用于以下内容:

event.headers
event.headers["X-Requested-With"]

var headerItem = "x-requested-with"
event.headers.headerItem
等等,似乎什么都没有定义

据Cloudwatch称,此次活动是:

{
    "resource": "/contactformlambda",
    "path": "/contactformlambda",
    "httpMethod": "POST",
    "headers": {
        "Accept": "application/json, text/plain, */*",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "en-US,en;q=0.9",
        "cache-control": "no-cache",
        "CloudFront-Forwarded-Proto": "https",
        "CloudFront-Is-Desktop-Viewer": "true",
        "CloudFront-Is-Mobile-Viewer": "false",
        "CloudFront-Is-SmartTV-Viewer": "false",
        "CloudFront-Is-Tablet-Viewer": "false",
        "CloudFront-Viewer-Country": "AU",
        "content-type": "text/plain",
        "Host": "ovo5xmxf7e.execute-api.ap-southeast-2.amazonaws.com",
        "origin": "http://localhost:4200",
        "pragma": "no-cache",
        "Referer": "http://localhost:4200/contact",
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36",
        "Via": "2.0 49d473f12cd3746d92748f257e16ca9e.cloudfront.net (CloudFront)",
        "X-Amz-Cf-Id": "7_PvRhkwbB7wmB1n8EFgE9s84q1xPYZ_uKwAjwYPXSv383M-fmDTgQ==",
        "X-Amzn-Trace-Id": "Root=1-5a826e92-b4425f8069686c808cc2d500",
        "X-Forwarded-For": "155.144.114.41, 54.240.152.46",
        "X-Forwarded-Port": "443",
        "X-Forwarded-Proto": "https",
        "x-requested-with": "Angular5"
    },
    "queryStringParameters": null,
    "pathParameters": null,
    "stageVariables": null,
    "requestContext": {
        "requestTime": "13/Feb/2018:04:50:26 +0000",
        "path": "/prod/contactformlambda",
        "accountId": "499908792600",
        "protocol": "HTTP/1.1",
        "resourceId": "i6i1qv",
        "stage": "prod",
        "requestTimeEpoch": 1518497426058,
        "requestId": "683aeec6-1079-11e8-a419-318ae32195ef",
        "identity": {
            "cognitoIdentityPoolId": null,
            "accountId": null,
            "cognitoIdentityId": null,
            "caller": null,
            "sourceIp": "155.144.114.41",
            "accessKey": null,
            "cognitoAuthenticationType": null,
            "cognitoAuthenticationProvider": null,
            "userArn": null,
            "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36",
            "user": null
        },
        "resourcePath": "/contactformlambda",
        "httpMethod": "POST",
        "apiId": "ovo5xmxf7e"
    },
    "body": "{\"subject\":\"Enquiry from ZenithWebFoundry\",\"name\":\"Mike\",\"number\":\"0415118180\",\"email\":\"rmjcoxon@gmail.com\",\"comment\":\"this is a test from localhost\"}",
    "isBase64Encoded": false
}

“x-requested-with”标题在那里,但它似乎从未定义过,当我试图以编程方式访问它时,它应该在
事件标题中

从,它说

{
    "resource": "Resource path",
    "path": "Path parameter",
    "httpMethod": "Incoming request's method name"
    "headers": {Incoming request headers}
    "queryStringParameters": {query string parameters }
    "pathParameters":  {path parameters}
    "stageVariables": {Applicable stage variables}
    "requestContext": {Request context, including authorizer-returned key-value pairs}
    "body": "A JSON string of the request payload."
    "isBase64Encoded": "A boolean flag to indicate if the applicable request payload is Base64-encode"
}

更新(基于您新提供的信息):

您要查找的标题是
x-request-with
而不是
x-request-with
(注意大小写)

请注意,Javascript中的对象查找区分大小写

如果要使用变量检索它,可以执行以下操作

var headerItem = "x-requested-with"
event.headers[headerItem]

如果它不在
event.headers
中,则会出现其他问题。您能否
console.log(event)
并将其包含在您的问题中?
var headerItem = "x-requested-with"
event.headers[headerItem]