小编can*_*sci的帖子

如何在 cloudfront 上使用调整图像 lambda 边缘函数来修复 503 错误?

我正在尝试根据文章使用 cloudfront 发行版调整图像大小:https ://aws.amazon.com/tr/blogs/networking-and-content-delivery/resizing-images-with-amazon-cloudfront-lambdaedge-aws-cdn -博客/

我在文章中使用给定的 Origin-Response 和 Viewer-Request 函数创建了项目文件夹,并下载了依赖项,使用 cloudformation 模板部署了 zip 包。

IAM 角色、s3 存储桶、存储桶策略、带有 lambda@edge 函数的分发创建时没有任何错误,而且它们似乎都兼容。

但是当我尝试调整原始存储桶中的图像大小时出现以下错误;

“503 错误无法满足请求。与 CloudFront 分配关联的 Lambda 函数无效或没有所需的权限。”

我也没有看到任何关于监控的内容,这意味着我的功能没有被调用。

我创建了另一个具有“AdministratorAccess”策略和信任关系的管理员角色“edgelambda.amazonaws.com”、“lambda.amazonaws.com”

我将我的存储桶策略更改为所有公共。

我可以查看图像,但是当我尝试通过将查询字符串添加到 cloudfront 分发 url 来调整大小时仍然出现 503 错误

“xxxxxxxxx.net/images/pexels.jpeg?d=100x100”

这是我的存储桶、存储桶策略、IAM 角色和功能。

存储桶名称:image-resize-488052071209-us-east-1

Bukcet 政策:

{
    "Version": "2008-10-17",
    "Statement": [
        {
            "Sid": "AllowPublicRead",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::image-resize-488052071209-us-east-1/*"
        },
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::image-resize-488052071209-us-east-1/*"
        },
        {
            "Effect": "Allow",
            "Principal": …
Run Code Online (Sandbox Code Playgroud)

amazon-s3 amazon-web-services amazon-iam aws-lambda aws-lambda-edge

6
推荐指数
1
解决办法
3131
查看次数