The purpose of this excercise is to demonstrate how to access S3 Objects from a different AWS Account - called "Cross Account S3 Access"
- Have 2 Different AWS Accounts (Hard Requirement) (Account A / Account B)
- Create a Bucket in Account A (Or Reuse an existing S3 Bucket if you have it ready)
- Upload Objects to the Bucket
- Access the S3 Bucket from "Account B"
# ~/.aws/config file
[profile training-cross-account-role]
role_arn = arn:aws:iam::<Account B>:role/Training2CrossAccountRole
credential_source = EcsContainer
aws s3api list-objects-v2 --bucket <bucket in Account A> --profile training-cross-account-role
{
"Sid": "CrossAccountFetch",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<Account B>:role/Training2CrossAccountRole"
},
"Action": [
"s3:ListBucket",
"s3:ListBucketVersions",
"s3:GetObject",
"s3:GetObjectVersion"
],
"Resource": [
"arn:aws:s3:::<S3 Bucket>/*",
"arn:aws:s3:::<S3 Bucket>"
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:ListBucketVersions",
"s3:GetObject",
"s3:GetObjectVersion"
],
"Resource": [
"arn:aws:s3:::<S3 Bucket>/*",
"arn:aws:s3:::<S3 Bucket>"
]
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<Account B:user/<User>"
},
"Action": "sts:AssumeRole"
}
]
}