Put Object to S3 Bucket of another account

MostlyJava

We are able to put objects into our S3 Bucket.

But now we have a requirement that we need to put these Object directly to an S3 Bucket which belongs to a different account and different region.

Here we have few questions:

  • Is this possible?
  • If possible what changes we need to do for this?

They have provided us Access Key, Secret Key, Region, and Bucket details.

Any comments and suggestions will be appreciated.

John Rotenstein

IAM credentials are associated with a single AWS Account.

When you launch your own Amazon EC2 instance with an assigned IAM Role, it will receive access credentials that are associated with your account.

To write to another account's Amazon S3 bucket, you have two options:

Option 1: Your credentials + Bucket Policy

The owner of the destination Amazon S3 bucket can add a Bucket Policy on the bucket that permits access by your IAM Role. This way, you can just use the normal credentials available on the EC2 instance.

Option 2: Their credentials

It appears that you have been given access credentials for their account. You can use these credentials to access their Amazon S3 bucket.

As detailed on Working with AWS Credentials - AWS SDK for Java, you can provide these credentials in several ways. However, if you are using BOTH the credentials provided by the IAM Role AND the credentials that have been given to you, it can be difficult to 'switch between' them. (I'm not sure if there is a way to tell the Credentials Provider to switch between a profile stored in the ~/.aws/credentials file and those provided via instance metadata.)

Thus, the easiest way is to specify the Access Key and Secret Key when creating the S3 client:

BasicAWSCredentials awsCreds = new BasicAWSCredentials("access_key_id", "secret_key_id");
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                        .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
                        .build();

It is generally not a good idea to put credentials in your code. You should load them from a configuration file.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AWS Lambda triggered by PUT to s3 bucket in separate account

From Dev

How to transfer an Amazon S3 bucket to another account?

From Dev

Can I add multiple tags to a S3 bucket and not an object using put_bucket_tagging?

From Dev

S3: User cannot access object in his own s3 bucket if created by another user

From Dev

S3 bucket policy, how to ALLOW a IAM group from another account?

From Dev

configure Amazon s3 bucket to run Lambda function created in another account

From Dev

configure Amazon s3 bucket to run Lambda function created in another account

From Dev

How to fetch an image from one bucket and put it in another in S3 boto

From Dev

Not able to Put data/object into S3 bucket using Glue Job when KMS Encryption is enabled

From Dev

Copy an Amazon s3 object to another folder in another bucket.

From Dev

how to copy s3 object from one bucket to another using python boto3

From Dev

AWS S3 incorrect bucket object

From Dev

S3: The bucket can not be accessed by its root account?

From Dev

New to S3, not sure what to put in my Bucket Policy

From Dev

AWS S3 permissions - error with put-bucket-acl

From Dev

AWS Lambda: How to read CSV files in S3 bucket then upload it to another S3 bucket?

From Dev

Catching an error with put object and s3

From Dev

Catching an error with put object and s3

From Java

AWS S3 bucket cross account policy mixed with internal account

From Dev

Transfer S3 bucket contents from one account to other account in different regions

From Dev

Copy to Redshift from another accounts S3 bucket

From Dev

Get Absolute Path of Each S3 Object in Bucket

From Dev

Get AWS S3 Bucket Object Using PowerShell DSC

From Dev

How do I edit an AWS S3 Bucket Object?

From Dev

object exists in AWS S3 bucket in Node.JS

From Dev

Delete object from AWS S3 bucket (not in code)

From Java

AWS S3: How to change an HTTP Header of a single object in a S3 bucket via CLI?

From Dev

How to download all the contents of an S3 bucket and then upload to another bucket?

From Dev

Copying an s3 bucket to another bucket is too slow, how can I do it faster?

Related Related

  1. 1

    AWS Lambda triggered by PUT to s3 bucket in separate account

  2. 2

    How to transfer an Amazon S3 bucket to another account?

  3. 3

    Can I add multiple tags to a S3 bucket and not an object using put_bucket_tagging?

  4. 4

    S3: User cannot access object in his own s3 bucket if created by another user

  5. 5

    S3 bucket policy, how to ALLOW a IAM group from another account?

  6. 6

    configure Amazon s3 bucket to run Lambda function created in another account

  7. 7

    configure Amazon s3 bucket to run Lambda function created in another account

  8. 8

    How to fetch an image from one bucket and put it in another in S3 boto

  9. 9

    Not able to Put data/object into S3 bucket using Glue Job when KMS Encryption is enabled

  10. 10

    Copy an Amazon s3 object to another folder in another bucket.

  11. 11

    how to copy s3 object from one bucket to another using python boto3

  12. 12

    AWS S3 incorrect bucket object

  13. 13

    S3: The bucket can not be accessed by its root account?

  14. 14

    New to S3, not sure what to put in my Bucket Policy

  15. 15

    AWS S3 permissions - error with put-bucket-acl

  16. 16

    AWS Lambda: How to read CSV files in S3 bucket then upload it to another S3 bucket?

  17. 17

    Catching an error with put object and s3

  18. 18

    Catching an error with put object and s3

  19. 19

    AWS S3 bucket cross account policy mixed with internal account

  20. 20

    Transfer S3 bucket contents from one account to other account in different regions

  21. 21

    Copy to Redshift from another accounts S3 bucket

  22. 22

    Get Absolute Path of Each S3 Object in Bucket

  23. 23

    Get AWS S3 Bucket Object Using PowerShell DSC

  24. 24

    How do I edit an AWS S3 Bucket Object?

  25. 25

    object exists in AWS S3 bucket in Node.JS

  26. 26

    Delete object from AWS S3 bucket (not in code)

  27. 27

    AWS S3: How to change an HTTP Header of a single object in a S3 bucket via CLI?

  28. 28

    How to download all the contents of an S3 bucket and then upload to another bucket?

  29. 29

    Copying an s3 bucket to another bucket is too slow, how can I do it faster?

HotTag

Archive