RMish
RMish

Reputation: 151

How to put the objectacl by not wiping the current ACL

I am using the below line of codes, however the ACL of only 'owner-account' is applied and the one with 'child-account' doesn't get applied. how to get this fixed. this is more a question related to dictionary I guess..Any help is appreciated.

import json import boto3 import logging

def lambda_handler(event, context): s3 = boto3.resource('s3')

object_acl = s3.ObjectAcl('bucket_name','bucket_key')
response = object_acl.put(

AccessControlPolicy={
    'Grants': [
        {
            'Grantee': {


                'ID':'child-account',
                'Type': 'CanonicalUser'

            },
            'Grantee': {


                'ID':'owner-account',
                'Type': 'CanonicalUser'

            },
            'Permission': 'FULL_CONTROL'
        },
    ],
    'Owner': {

            'ID': 'ssm-service-internal-account'
    }
})



print(response)

Upvotes: 0

Views: 53

Answers (1)

jellycsc
jellycsc

Reputation: 12259

The dictionary structure is wrong. It should be like this

AccessControlPolicy={
    'Grants': [
        {
            'Grantee': {
                'ID':'child-account',
                'Type': 'CanonicalUser'

            },
            'Permission': 'FULL_CONTROL'
        },
        {
            'Grantee': {
                'ID':'owner-account',
                'Type': 'CanonicalUser'

            },
            'Permission': 'FULL_CONTROL'
        }
    ],
    'Owner': {
        'ID': 'ssm-service-internal-account'
    }
})

Upvotes: 1

Related Questions