Ritwik Singh
Ritwik Singh

Reputation: 99

executing lambda on s3 bucket ObjectCreated event in cloudformation

I have a requirement to launch a number of lambda functions on the ObjectCreated event in a number of s3 buckets. But the architecture of my application requires modularity thus, I have to create two different templates, one for my bucket creation and another for the lambdas. According to me, one way to achieve this is by using the SNS service.

SNS

we create the SNS topic in the buckets creation template and provide the ObjectCreated event to it through NotificationConfiguration property of the s3. In the lambda template we can subscribe the lambda to the above mentioned SNS topic and the lambda function will be called on the s3 ObjectCreated event. But again the architecture does not allows using SNS.

Possible way

Is it all possible to do this without using SNS and compromising on the modularity like making two separate templates for buckets and lambdas and using their notification configuration in a third template to complete the chain.

Final Question

I can not use SNS and I want modularity, how can I call my lambda functions on the s3 event? is it even ossible with my restrictions? thank you

Upvotes: 0

Views: 767

Answers (1)

Braydon
Braydon

Reputation: 251

You could trigger your functions straight from S3 using events in the bucket properties. http://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html

You could also use a CloudWatch Event Rule to trigger your functions. To do so:

  1. Go to your AWs Console and select Services > CloudWatch.
  2. Select Rules under Events on the left.
  3. Select Create Rule.
  4. Leave Event Pattern selected.
  5. Select Simple Storage Service (S3) from Service Name drop down.
  6. Select Object Level Operations from Event Type drop down.
  7. Select Specific operation(s).
  8. Select PutObject from drop down.
  9. Select Specific bucket(s) by name.
  10. Enter bucket names.
  11. Select + Add target* on the right.
  12. Select Lambda function to trigger.
  13. Select Configure details at the bottom of the page.
  14. Enter a rule name.
  15. Finish by selecting Create rule.

Upvotes: 1

Related Questions