是否可以通过 VPC endpoints实现跨账户访问Amazon DynamoDB?

0

【以下的问题经过翻译处理】 Amazon DynamoDB 的终端节点文档在此处记录:https://docs.aws.amazon.com/vpc/latest/userguide/vpc-endpoints-ddb.html

我没有看到任何有关于跨账户访问Amazon DynamoDB 所需的终端节点设置. 这个是否被支持?我们的客户该如何实现?

profile picture
EXPERTE
gefragt vor 8 Monaten52 Aufrufe
1 Antwort
0

【以下的回答经过翻译处理】 您正在试图访问另一个账户中的DynamoDB表。 DynamoDB不支持基于资源的策略(例如S3、KMS、SQS等, 您访问DynamoDB时始终使用创建DynamoDB table的账户的主体身份。因此你可以通过在表格owner账户中assume一个角色来访问它。

以下是跨账户角色设置的过程:

  1. 在DynamoDB账户中创建具有对DynamoDB表格的访问权限的角色,下面是IAM设置的简单示例,注意您需要在<>块中填写变量:

DynamoDB角色信任策略:

{
    "Version": "2012-10-17",
    "Statement": {
        "Effect": "Allow",
        "Action": "sts:AssumeRole",
        "Principal": {
            "AWS": "arn:aws:iam::<AppAccountID>:root"
        }
    }
}

DynamoDB角色IAM策略:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:List*",
                "dynamodb:DescribeReservedCapacity*",
                "dynamodb:DescribeLimits",
                "dynamodb:DescribeTimeToLive"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:BatchGet*",
                "dynamodb:DescribeStream",
                "dynamodb:DescribeTable",
                "dynamodb:Get*",
                "dynamodb:Query",
                "dynamodb:Scan",
                "dynamodb:BatchWrite*",
                "dynamodb:CreateTable",
                "dynamodb:Delete*",
                "dynamodb:Update*",
                "dynamodb:PutItem"
            ],
            "Resource": "arn:aws:dynamodb:*:*:table/<TableName>"
        }
    ]
}
  1. 在另一个账户中创建一个允许assume DynamoDB角色的角色:

应用程序角色的IAM

{ "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Action": "sts:AssumeRole", "Resource": "arn:aws:iam::<DynamoDBAccountID>:role/<DynamoDBRoleName>" } }

3: 在您的应用程序中assume role, 以下是一个Python代码实例

AssumeRole.py

import boto3

def assumerole(account, rolename): sts_client = boto3.client('sts')

# Call the assume_role method of the STSConnection object and pass the role
# ARN and a role session name.
assumedRoleObject = sts_client.assume_role(
    RoleArn="arn:aws:iam::" + account + ":role/" + rolename,
    RoleSessionName=account + "-" + rolename.replace('/','')
)
return assumedRoleObject

4: 使用Assume Role的认证信息去执行DynamoDB命令

在网络侧, 你需要确认你应用程序所在的VPC已经有DynamoDB endpoint.

profile picture
EXPERTE
beantwortet vor 8 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen

Relevanter Inhalt