允许 Lambda 函数专门将对象放入 S3 存储桶

Allowing a Lambda function to exclusively put objects into an S3 bucket

我当前的 S3 存储桶策略在全局启用 s3:getObjects3:putObject,我试图通过指定存储桶策略来限制它。

虽然 s3:getObject 是安全的,但我想将对 s3:putObject 的访问限制为仅特定的 AWS Lambda 函数。

该函数通过对 CloudFront 的 HTTP 请求匿名触发,因此不涉及 AWS 用户。

如何通过 Lambda 的 ARN 标识符限制访问?

当前政策:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:getObject",
            "Resource": "arn:aws:s3:::{bucket_name}/*"
        },
        {
            "Sid": "LambdaPutObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:putObject",
            "Resource": "arn:aws:s3:::{bucket_name}/*"
        }
    ]
}

实际上,所需要的只是为 Lambda 创建一个访问策略。有预定义的,例如 lambda_basic_execution.

角色配置可以在里面的AWS控制台找到:

Lambda > Functions > {name} > Roles IAM > Roles

这是对我有帮助的特定配置:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": "arn:aws:logs:*:*:*"
        },
        {
            "Effect": "Allow",
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::{bucket_name}/*"
        }
    ]
}