gpt4 book ai didi

python - 使用 python 的 Lambda@edge 函数

转载 作者:太空宇宙 更新时间:2023-11-04 07:14:48 28 4
gpt4 key购买 nike

我们正在尝试编写一个 lambda@edge 函数来触发 viewer-request。我能够找到很多关于使用 JavaScript 的示例。

例如

'use strict';

exports.handler = (event, context, callback) => {
console.log('Event: ', JSON.stringify(event, null, 2));
console.log('Context: ', JSON.stringify(context, null, 2));
const request = event.Records[0].cf.request;

// You can also store and read the redirect map
// in DynamoDB or S3, for example.
const redirects = {
'/r/music': '/card/bcbd2481',
'/r/tree': '/card/da8398f4',
};

if (redirects[request.uri]) {
return callback(null, {
status: '302',
statusDescription: 'Found',
headers: {
'location': [{
key: 'Location',
value: redirects[request.uri] }]
}
});
}

callback(null, request);
};

以上代码将重定向匹配特定路径的请求。任何人都可以建议如何将类似的代码移植到 python 吗?或共享有关部署 python lambda@edge 函数的资源/信息。

谢谢

最佳答案

Lambda@Edge 以前 只允许 Node.js,所以在最初提出这个问题时,无法在 Python 或除 Node 之外的任何其他语言中创建 Lambda@Edge 函数。 js(或在 Node.js 包装器内)。

截至 2018 年 8 月,Lambda@Edge 仅支持 Node.js 6.10 和 8.10 运行时环境。

Lambda@Edge 现在支持 Node.js 8.10、Node.js 10.x 和 Python 3.7 ,截至 2019 年 8 月。

边缘环境在许多方面与一般的 Lambda 产品明显不同:参见 Lambda Function Configuration and Execution Environment在 CloudFront 开发人员指南中。

关于python - 使用 python 的 Lambda@edge 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51783578/

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