使用python的Lambda @ edge函数

Mo *_*abi 1 python amazon-web-services aws-lambda

我们正在尝试编写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);
};
Run Code Online (Sandbox Code Playgroud)

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

谢谢

Mic*_*bot 7

Lambda @ Edge 以前仅允许使用Node.js,因此在最初提出此问题时,无法用Python或Node.js以外的任何其他语言(或在Node.js包装器中)创建Lambda @ Edge函数。 。

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

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

边缘环境在许多方面与常规Lambda产品明显不同:请参阅《 CloudFront开发人员指南》中的Lambda函数配置和执行环境。