尝试在区域之间复制快照时,Lambda 函数抛出“您无权执行此操作”

sla*_*eff 0 json amazon-ec2 amazon-web-services amazon-iam aws-lambda

我正在尝试运行一个测试函数,以便在 AWS 的 2 个区域之间复制单个快照(将来我想自动化它)。但是当我运行测试时它会抛出一个错误

"errorType": "ClientError", "errorMessage": "调用 CopySnapshot 操作时发生错误 (UnauthorizedOperation): 您无权执行此操作。"

这是我的 IAM 的样子:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:*"
            ],
            "Resource": "arn:aws:logs:*:*:*"
        },
        {
            "Effect": "Allow",
            "Action": "ec2:Describe*",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "ec2:CreateSnapshot",
                "ec2:DeleteSnapshot",
                "ec2:CreateTags",
                "ec2:ModifySnapshotAttribute",
                "ec2:ResetSnapshotAttribute"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

这是函数:

import boto3

def lambda_handler(event, context):
client = boto3.client('ec2')
client.copy_snapshot(SourceSnapshotId='snap-xxxxxxxxxxxxxxxxxxxxx',
                     SourceRegion='us-central-1',
                     DestinationRegion='eu-west-3')
Run Code Online (Sandbox Code Playgroud)

Joh*_*ein 5

您的政策还需要授予ec2:CopySnapshot许可。

提示:大多数权限与它们允许的命令名称相匹配!