Cloudformation - Send s3 notification to SQS for existing bucket

Viewed 528

How can Cloudformation send an s3 notification for an existing bucket to SQS?

I know how to send the notification to a lambda handler, but not sure how to do this for SQS. I also know I can send it to SQS if I create the bucket resource in Cloudformation and use NotificationConfiguration, but that's not an option for me, as the bucket already exists in another terraform config. The queue is also created in terraform.

I currently send the notification to a lambda proxy that then posts it to SQS, but that is not ideal.

Function:

  some_function:
    handler: app.apis.some_function.handler
    events:
      - s3:
          bucket: ${self:custom.someBucket} # arn var for existing bucket
          event: s3:ObjectCreated:*
          rules:
            - prefix: "some_prefix/"
          existing: true

Is there a way to adjust this config to send the notification directly to SQS instead of a lambda handler that acts as a proxy to SQS?

2 Answers

Sadly, you can't do this easily as the bucket and sqs queue are out of CFN's control. You could consider two options:

  • import them to CFN so that they are managed by it. But then this will lead to issues you you are also using terraform to manage them.
  • develop a custom resource in CFN which will be in the form of a lambda function. The function can use then AWS API to add the events to existing S3. This may also lead to issues, as terraform will not be aware of such changes.
Related