So in my company theres two S3 buckets, one stores all of the reports and another is supposed to store a particular type of report called accountingEOMReport which is ran once a month, right now we're trying to pull the EOM reports from bucket 1 but the code isn't saving it there, instead it's saving to bucket 4 (this wasn't a problem before and only started after we began using S3). What I want to do is create some sort of policy rule or Lambda function to automatically search bucket for for a particular type of file name (eg EOMReport or something like that) and move those to bucket 1, maybe once per day or a few times a week. This report is run once or a few times a month so maybe to the storage option that works best for that but that can still be retrieved within a few hours max worst case scenario.
CodePudding user response:
You can:
- Configure the Amazon S3 bucket to trigger an AWS Lambda function whenever a new object is created
- You could then code the AWS Lambda function to check the name of the object that was created. If it is an
EOMReport
, then the Lambda function should:- Copy the object to the other bucket
- Delete the original object (if desired)
This will happen immediately upon creation of the object, so there is no need to schedule it. AWS Lambda is charged per-millisecond and there is a monthly Free Tier for AWS Lambda. As a result, this solution will likely not cost you anything.