I have 400+ buckets in my AWS account some of which can be accessed by users using user group dev-user-group & prod-user-group. Few S3 buckets's policies are something like this
"aws:arn": [
"arn:aws:sts::123XXXXX43:assumed-role/dev-user-group/*"
"arn:aws:sts::123XXXXX43:assumed-role/prod-user-group/*"
]
Now, we would like to change it to the following
"aws:arn": [
"arn:aws:sts::123XXXXX43:assumed-role/dev-eid/*"
"arn:aws:sts::123XXXXX43:assumed-role/dev-p-eid/*"
"arn:aws:sts::123XXXXX43:assumed-role/prod-eid/*"
"arn:aws:sts::123XXXXX43:assumed-role/prod-p-eid/*"
]
Few buckets have only any one of accesses & few don't have any access. We would like to automate the process for updating the bucket policies using a script such that the script need to check if dev-user-group & prod-user-group is defined in the bucket policies. If so, it should remove them & add new policies.
I hope I conveyed better. Kindly give me suggestions on this.
You will need to create quick script and use the aws cli for this.
The script will first list all the buckets you have in the account
aws s3 ls
then save that list and loop over the list of buckets using this command which will output the policy as a json file:You can then modify the
policy.json
file as needed. Finally you can apply this modified policy back to the S3 bucket by running:Source