Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
Copy files from one AWS account's S3 bucket to another AWS account's S3 bucket + using NodeJS

How to copy files from source AWS account's S3 bucket into destination S3 bucket which is on a different AWS account using NodeJS ?

i.e, from S3 in AWS Account A to S3 in AWS Account B

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Did you try the copyObject method?

Use Bucket and Key to indicate the destination and CopySource to indicate the source object. Make sure your creds have permission to both read the source object and write the destination object.

Ideally, improve the security of your copy by asserting the AWS account ID of the destination bucket in ExpectedBucketOwner, if you know it.

Here's an untested example:

const s3 = new AWS.S3();

const params = {
  Bucket: 'destbucket', 
  CopySource: 'srcbucket/srcfolder/file.txt', 
  Key: 'destfolder/file.txt'
};

const result = await s3.copyObject(params).promise();

If you need to assume a role that allows access to both buckets, then use some variant of this code to get STS credentials and an S3 client object:

const sts = new AWS.STS({ region: 'us-west-2' });

const role_params = {
  RoleArn: 'arn:aws:iam::1234567890:role/yourrole',
  RoleSessionName: 'optional-name',
  ExternalId: 'some-optional-value',
  DurationSeconds: 3600,
};

const res = await sts.assumeRole(role_params).promise();

const cred_params = {
  accessKeyId: res.Credentials.AccessKeyId,
  secretAccessKey: res.Credentials.SecretAccessKey,
  sessionToken: res.Credentials.SessionToken,
};

const s3 = await new AWS.S3(cred_params);

To understand the permissions needed for cross-account S3 access, see How can I provide cross-account access to objects that are in Amazon S3 buckets?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!