AWS Lambda无法删除Amazon S3对象 [英] AWS Lambda can't delete Amazon S3 object

查看:205
本文介绍了AWS Lambda无法删除Amazon S3对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个AWS Lambda函数,该函数处理上传到第一个存储桶的文件,然后将其保存到第二个存储桶,然后删除输入文件.

I'm trying to create an AWS Lambda function, which processes a file uploaded to the first bucket, then saves it to the second bucket and then deletes the input file.

问题是,当我尝试删除文件时,

The problem is that when I'm trying to delete the file I'm getting

{
  "message": "Access Denied",
  "code": "AccessDenied",
  "time": "2015-02-09T22:08:45.926Z",
  "statusCode": 403,
  "retryable": false,
  "retryDelay": 30
}

试图删除文件的代码段为

The code snippet, which tries to delete the file is

s3.deleteObject({
    Bucket: inputBucket,
    Key: inputKey
}, function(a, b) {
    if (a) {
        console.error("Error on delete");
        console.error(a);
    } else {
        console.log("Deleted successfully");
    }
});

推荐答案

lambda无法删除文件(S3对象)的可能原因可能是Lambda的执行角色.

The possible reason why lambda wasn't able to delete the file ( S3 object ) could be due to the Lambda's Execution Role.

解决此问题的步骤

  1. 在AWS管理控制台中导航到IAM
  2. 查找为lambda使用(或创建的)IAM角色(如果默认,则为lambda_exec_role)
  3. 转到附加角色策略->自定义策略,然后添加以下IAM策略文档


{
  "Statement": [
    {
      "Sid": "Stmt1423535846414",
      "Action": [
        "s3:DeleteObject"
      ],
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::*"
    }
  ]
}

这篇关于AWS Lambda无法删除Amazon S3对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆