Reputation: 119
My use-case:
I have two different aws accounts.
Let’s assume in Account-A i have 2 buckets. One is bucket-east-A in east region and bucket-west-A in west region.
Similarly in Account-B i have bucket-east-B in east region and bucket-west-B in west region.
Using lambda function I’m copying bucket-east-A objects to bucket-east-B (cross account push) whenever there’s any new data uploaded to bucket-east-A by copyobject() method. Now, i need to push objects from the west region bucket in Account-A to west region bucket in Account-B, this has to be done in same lambda function with some conditional statement. I’ve tried lot many ways but failed. I’m using python language to do this. I’m completely new to IT world. Can someone please help me with appropriate conditional statement or any other way to achieve this.
Upvotes: 0
Views: 397
Reputation: 269101
Your AWS Lambda function is always going from Account-A -> Account-B
, so it should be easy.
When an Amazon S3 Event is configured on a bucket, an AWS Lambda function can be nominated. The event will then trigger the nominated Lambda function whenever an object is added to the bucket.
You should configure both Bucket-east-A
and Bucket-west-A
to trigger the same Lambda function.
When the Lambda function is invoked, the function is supplied with the Bucket Name and Key (filename) of the object that caused the Lambda function to be triggered. The Lambda function should then look at the source bucket and then select the appropriate destination bucket:
Bucket-east-A
then destination bucket is Bucket-east-B
Bucket-west-A
then destination bucket is Bucket-west-B
The rest of the code should remain the same, since you apparently have it working already.
Upvotes: 1