I have to create a Nodejs script to perform the S3 bucket to bucket sync. I don't want to run this when a file is just uploaded to the master S3, so I think lambda is not an option. I need to run the task daily once at a particular time.
How can I achieve this S3 bucket sync using NodeJS using aws-sdk?
Cron can be used for scheduling. I found only aws-sdk code to copy from S3 to another S3. Do we have a code in place to sync two S3 buckets?
CodePudding user response:
You will need a cron job and nodejs provides a library named node-cron
let cron = require('node-cron');
cron.schedule('* * * * *', () => {
// TODO
...
});
For daily cron you can use something like
0 0 * * *
The first 0 specifies the minutes and the second the hours so this cron will run every day at midnight.
CodePudding user response:
AWS S3 Bucket synchronization using Nodejs and aws-sdk
can be performed by the method of the s3sync package. If you use it with node-cron
, you will be able to implement AWS S3 bucket synchronization scheduling through Nodejs.
I don't know if it'll help, if Cron and aws-cli are available, the purpose can be achieved without Nodejs.
You simply add the code below to the crontab
.
0 0 * * * aws s3 sync s3://bucket-name-1 s3://bucket-name-2