简体   繁体   English

获取AWS Glue以写入另一个AWS账户中的S3存储桶

[英]Getting AWS Glue to write to an S3 bucket in another AWS account

I need to have AWS Glue (Account:PROD) to write to an S3 Bucket on another account (Account:DEV) 我需要使用AWS Glue(帐户:PROD)写入另一个帐户的S3 Bucket(帐户:DEV)

According to http://docs.aws.amazon.com/glue/latest/dg/access-control-overview.html 根据http://docs.aws.amazon.com/glue/latest/dg/access-control-overview.html

Resource-Based Policies 基于资源的政策

Other services, such as Amazon S3, also support resource-based permissions policies. 其他服务(如Amazon S3)也支持基于资源的权限策略。 For example, you can attach a policy to an S3 bucket to manage access permissions to that bucket. 例如,您可以将策略附加到S3存储桶以管理对该存储桶的访问权限。 AWS Glue doesn't support resource-based policies. AWS Glue不支持基于资源的策略。

...which means that I cannot do arn:aws:s3::DEV-Account:S3-Bucket/* ...这意味着我不能做arn:aws:s3::DEV-Account:S3-Bucket/*

I tried creating a Trusted entity on the DEV Account with PROD and attached a policy set to access the s3 bucket on the DEV account. 我尝试使用PROD在DEV帐户上创建一个Trusted entity ,并附加了一个策略集来访问DEV帐户上的s3存储桶。

How do I go about this? 我该怎么做?

We had the same issue and we came to a solution by adding these into our DEV bucket policies: 我们遇到了同样的问题,我们通过将这些添加到DEV存储桶策略中来解决问题:

{
    "Sid": "SID",
    "Effect": "Allow",
    "Principal": {
        "AWS": "arn:aws:iam::[PROD-ACCOUNT-ID]:role/[PROD-GLUE-ROLE]"
    },
    "Action": [
        "s3:Get*",
        "s3:Put*",
        "s3:ListBucket",
        "s3:ListBucketMultipartUploads",
        "s3:ListBucketVersions",
        "s3:ListMultipartUploadParts"
    ],
    "Resource": [
        "arn:aws:s3:::[DEV-BUCKET]",
        "arn:aws:s3:::[DEV-BUCKET]/*"
    ]
}

And this to the PROD Glue role ([PROD-GLUE-ROLE]) account policies: 这对于PROD Glue角色([PROD-GLUE-ROLE])帐户政策:

{
    "Action": [
        "s3:Get*",
        "s3:List*"
        "s3:Put*"
    ],
    "Resource": [
        "arn:aws:s3:::[DEV-BUCKET]*"
    ],
    "Effect": "Allow"
}

After that you should be able to read and write data from and to your DEV bucket using your PROD role in the PROD account: 之后,您应该能够使用PROD帐户中的PROD角色从DEV桶读取数据和向其读取数据:

data_frame = glue_context.create_dynamic_frame_from_options(
    connection_type='s3',
    connection_options={
        'paths':'s3://[DEV-BUCKET]/...'
    },
    format='json'
)

Hope this helps 希望这可以帮助

Just an update that Glue now supports Resource Level Policies, but currently only for DataCatalog resources. 只是Glue现在支持资源级别策略的更新,但目前仅适用于DataCatalog资源。 https://docs.aws.amazon.com/glue/latest/dg/glue-resource-policies.html https://docs.aws.amazon.com/glue/latest/dg/glue-resource-policies.html

We were able to get around this by having the GLUE Job add an ACL to the object it was creating and uploading to the S3 bucket 我们能够通过让GLUE Job为其创建的对象添加ACL并上传到S3存储桶来解决这个问题

ACL = {
u'Owner': {u'DisplayName': 'prod', u'ID': 'XXXX'
},
u'Grants': [{
    u 'Grantee': {
        u 'Type': 'CanonicalUser',
        u 'DisplayName': 'prod',
        u 'ID': 'XXXXX'
    },
    u 'Permission': 'FULL_CONTROL'
},
{
    u 'Grantee': {
        u 'Type': 'CanonicalUser',
        u 'DisplayName': 'dev',
        u 'ID': 'YYYY'
    },
    u 'Permission': 'READ'
},
{
    u 'Grantee': {
        u 'Type': 'CanonicalUser',
        u 'DisplayName': 'dev',
        u 'ID': 'YYYY'
    },
    u 'Permission': 'READ_ACP'
},
{
    u 'Grantee': {
        u 'Type': 'CanonicalUser',
        u 'DisplayName': 'dev',
        u 'ID': 'YYYY'
    },
    u 'Permission': 'WRITE_ACP'
}
]
response = client.put_object_acl(Bucket='BUCKET', Key='OBJECT', AccessControlPolicy=ACL)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM