gpt4 book ai didi

node.js - 无法读取exports.handler处未定义的属性 '0'(/var/task/index.js :4:34)

转载 作者:太空宇宙 更新时间:2023-11-04 01:30:45 24 4
gpt4 key购买 nike

我创建了一个 Lambda 函数,当我尝试执行该函数时抛出错误

'use strict';

exports.handler = (event, context, callback) => {

const request = event.Records[0].cf.request;
const headers = request.headers;
const origin = request.origin;
const client_IP = request.clientIp;
console.log(JSON.stringify(event));

//Setup the two different origins
const originA = "cloudfront-S3-origin1";
const originB = "Cloudfront-S3-origin2";
if (client_IP == "xx.xx.xx.xx") {
origin.s3.domainName = originA;
} else {
origin.s3.domainName = originB;
}
callback(null, request);
};

最佳答案

您的 Lambda 函数要么通过手动触发,要么以某种方式错过了 event.Records。我想建议您在使用类似

之前检查可用数据
'use strict';

exports.handler = (event, context, callback) => {
if(!event.Records) {
return callback(new Error('Records not available'));
}

const request = event.Records[0].cf.request;
const headers = request.headers;
const origin = request.origin;
const client_IP = request.clientIp;
console.log(JSON.stringify(event));

//Setup the two different origins
const originA = "cloudfront-S3-origin1";
const originB = "Cloudfront-S3-origin2";
if (client_IP == "xx.xx.xx.xx") {
origin.s3.domainName = originA;
} else {
origin.s3.domainName = originB;
}
callback(null, request);
};

关于node.js - 无法读取exports.handler处未定义的属性 '0'(/var/task/index.js :4:34),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56235604/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com