I have two S3 buckets with two different set of access and secret keys. Here is the set:
Bucket1, Key1, Secret1
And
Bucket2, Key2, Secret2, Token
I am trying to trigger S3-S3 copy via aws cli
like this:
aws s3 cp s3://key1:secret1@Bucket1 s3://key2:secret2@Bucket2
I have few questions:
aws cli
allows specifying key and secret as part of S3 Url ?What would be the best approach to achieve this use case ?
Depending on your use case, you can perform the data transfer between buckets using one of the following options: Run parallel uploads using the AWS Command Line Interface (AWS CLI) Use an AWS SDK. Use cross-Region replication or same-Region replication.
To copy an object between buckets, you must make sure that the correct permissions are configured. To copy an object between buckets in the same AWS account, you can set permissions using IAM policies.
Create S3 Bucket in Source Account, to which the logs will be uploaded. Add below Bucket Access policy to the IAM Role created in Destination account. Lambda function will assume the Role of Destination IAM Role and copy the S3 object from Source bucket to Destination.
You can't transfer Amazon S3 bucket ownership between AWS accounts because the bucket is always owned by the account that created it. Instead, you can copy Amazon S3 objects from one bucket to another so that you give ownership of the copied objects to the destination account.
To copy a file between Amazon S3 buckets, you must use credentials that have permission to access both buckets, or apply a bucket policy to the destination bucket that permits the access.
It is not possible to specify two sets of credentials because the AWS Command-Line Interface (CLI) is only calling a single AWS API, which performs the copy 'from' the source bucket directly to the destination bucket. The AWS CLI does not download the object -- it simply tells S3 to copy the object to another bucket (which can even be in a different region).
Therefore, you should create a bucket policy on the destination bucket that permits the credentials being used (User or Role) to PutObject
into the destination bucket.
The policy would be similar to:
{
"Version": "2012-10-17",
"Id": "Policy1",
"Statement": [
{
"Sid": "Stmt1",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::ACCOUNT-NUMBER:role/ROLE-NAME"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::DESTINATION-BUCKET/*"
}
]
}
The above is assuming the command is being called from an Amazon EC2 instance with an assigned role. To call from User credentials, use:
"AWS": "arn:aws:iam::ACCOUNT-NUMBER:user/USER-NAME"
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