While working with multiple AWS you may find yourself in need to access an S3 bucket which is hosted in a different account. we will be using account A and account B as follows.

Account A which has the S3 bucket.
Account B which wants to access the S3 bucket

Account B create an IAM user.
Create an IAM Access Policy as follows, this bucket allows access to the the account A bucket.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::Account-A-BucketName/*"
 
        }
    ]
}

Attach this IAM Policy to the user.

Account A create S3 bucket.
Create following bucket policy and apply it to the bucket.
Replace your username and account ID in the Principal section. This policy allows bucket to be access from that specific user from account B.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::AccountB:user/AccountBUserName"
            },
            "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::AccountABucketName/*"
            ]
        }
    ]
}

you can add or remove permission in the Action section according to your need but remember to do it in both of the accounts in user policy and also in the bucket policy.

That’s it with these setting you will be able to access the s3 buckets from different accounts. Let us know if this worked.