使用 Codebuild 将 DynamoDB 导出到 S3 到另一个帐户

发布于 2025-01-12 12:12:24 字数 2181 浏览 0 评论 0原文

我创建了一个代码构建来运行以下命令。

      aws dynamodb export-table-to-point-in-time \
        --table-arn arn:aws:dynamodb:REDACTED:REDACTED:table/REDACTED \
        --s3-bucket REDACTED \
        --s3-bucket-owner REDACTED

我还创建了一个 service-role 并附加了以下内联策略。

        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject"
            ],
            "Resource": [
                "arn:aws:s3:::REDACTED/*",
                "arn:aws:s3:::REDACTED"
            ]
        }

最后,我更新了 S3 存储桶,以允许 service-role 写入该存储桶:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::REDACTED:role/service-role/REDACTED"
            },
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::REDACTED/*",
                "arn:aws:s3:::REDACTED"
            ]
        }
    ]
}

codebuild 正确调用了命令,但由于权限问题导出失败。

[Container] 2022/03/08 11:50:42 Running command aws dynamodb export-table-to-point-in-time \
  --table-arn arn:aws:dynamodb:REDACTED:REDACTED:table/REDACTED \
  --s3-bucket REDACTED \
  --s3-bucket-owner REDACTED
{
    "ExportDescription": {
        "ExportArn": "arn:aws:dynamodb:REDACTED:REDACTED:table/REDACTED/export/REDACTED",
        "ExportStatus": "IN_PROGRESS",
        "StartTime": "2022-03-08T11:50:46.714000+00:00",
        "TableArn": "arn:aws:dynamodb:REDACTED:REDACTED:table/REDACTED",
        "TableId": "REDACTED",
        "ExportTime": "2022-03-08T11:50:46.714000+00:00",
        "ClientToken": "REDACTED",
        "S3Bucket": "REDACTED",
        "S3BucketOwner": "REDACTED",
        "S3SseAlgorithm": "AES256",
        "ExportFormat": "DYNAMODB_JSON"
    }
}
[Container] 2022/03/08 11:50:46 Phase complete: BUILD State: SUCCEEDED

输入图片此处描述

如果我从 AWS 控制台调用(即作为我的用户),我可以导出跨账户。但是使用 codebuild 和上面的命令,它失败了。

我缺少什么?

I've created a codebuild to run the following command.

      aws dynamodb export-table-to-point-in-time \
        --table-arn arn:aws:dynamodb:REDACTED:REDACTED:table/REDACTED \
        --s3-bucket REDACTED \
        --s3-bucket-owner REDACTED

I've also created a service-role and attached the following inline policy.

        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject"
            ],
            "Resource": [
                "arn:aws:s3:::REDACTED/*",
                "arn:aws:s3:::REDACTED"
            ]
        }

Finally, I've updated the S3 bucket to allow the service-role to write to the bucket:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::REDACTED:role/service-role/REDACTED"
            },
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::REDACTED/*",
                "arn:aws:s3:::REDACTED"
            ]
        }
    ]
}

The codebuild invokes the command correctly, but the export fails because of permissions.

[Container] 2022/03/08 11:50:42 Running command aws dynamodb export-table-to-point-in-time \
  --table-arn arn:aws:dynamodb:REDACTED:REDACTED:table/REDACTED \
  --s3-bucket REDACTED \
  --s3-bucket-owner REDACTED
{
    "ExportDescription": {
        "ExportArn": "arn:aws:dynamodb:REDACTED:REDACTED:table/REDACTED/export/REDACTED",
        "ExportStatus": "IN_PROGRESS",
        "StartTime": "2022-03-08T11:50:46.714000+00:00",
        "TableArn": "arn:aws:dynamodb:REDACTED:REDACTED:table/REDACTED",
        "TableId": "REDACTED",
        "ExportTime": "2022-03-08T11:50:46.714000+00:00",
        "ClientToken": "REDACTED",
        "S3Bucket": "REDACTED",
        "S3BucketOwner": "REDACTED",
        "S3SseAlgorithm": "AES256",
        "ExportFormat": "DYNAMODB_JSON"
    }
}
[Container] 2022/03/08 11:50:46 Phase complete: BUILD State: SUCCEEDED

enter image description here

If I invoke from the AWS Console (i.e. as my user) I am able to export cross account. But using codebuild and the command above, it fails.

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

◇流星雨 2025-01-19 12:12:24

我修好了这个。

问题是在 aws dynamodb export-table-to-point-in-time CLI 命令中引用了错误的 accountId。

I fixed this.

The issue was referencing the wrong accountId within the aws dynamodb export-table-to-point-in-time CLI command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文