I created two profiles (one for source and one for target bucket) and using below command to copy:
aws s3 cp --profile source_profile s3://source_bucket/file.txt --profile target_profile s3://target_profile/
But it throws below error.
fatal error: An error occurred (403) when calling the HeadObject operation: Forbidden
Looks like we can't use multiple profiles with aws commands.
Open AWS CLI and run the copy command from the Code section to copy the data from the source S3 bucket. Run the synchronize command from the Code section to transfer the data into your destination S3 bucket. Your data is then copied from the source S3 bucket to the destination S3 bucket.
Step 1: Create an IAM policy like the one below, replace the source and destination bucket names. Step 2: Attach the above policy to the IAM user or role that is doing the copy object operation. Step 3: Change the Object ownership to Bucket owner preferred in the destination bucket.
You can also use S3 Lifecycle policies to automatically transition objects between storage classes without any application changes.
The simplest method is to grant permissions via a bucket policy.
Say you have:
Add a bucket policy on Bucket-B:
{
"Id": "CopyBuckets",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "GrantAccessToUser-A",
"Action": "s3:*",
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::bucket-b",
"arn:aws:s3:::bucket-b/*"
],
"Principal": {
"AWS": [
"arn:aws:iam::<account-a-id>:user/user-a"
]
}
}
]
}
Then just copy the files as User-A.
See also: aws sync
between S3 buckets on different AWS accounts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With