Hello <#CL09KU1K7|> I have setup a Webhook that wi...
# ask-community
a
Hello #CL09KU1K7 I have setup a Webhook that will receive notifications from AWS SNS. The notifications will be about new files being created in a S3 Bucket. I want to capture the name of the new files created in the Bucket using the Webhook's template. The body of the notification looks like this (I've removed some fields for simplicity and formatted it for clarity):
Copy code
{
'Type': 'Notification',
'MessageId': 'd4aa09a0-6d51-5219-bcb2-68b12345bd7b',
'TopicArn': 'arn:aws:sns:us-east-1:1234567890:sns_topic',
'Subject': 'Amazon S3 Notification',
'Message': '{
  "Records":
    [
      {
        "eventVersion":"2.1",
        "eventSource":"aws:s3",
        "eventTime":"2025-08-12T16:25:24.066Z",
        "s3":{"s3SchemaVersion":"1.0","configurationId":"New file",
          "bucket":{"name":"testing.data","arn":"arn:aws:s3:::testing.data"},
          "object":{"key":"data_file.csv","size":34}
        }
      }
    ]
  }',
'Timestamp': '2025-08-12T16:25:24.883Z',
}
I want to capture the object key "_data_file.csv_" but i haven't been able to. What I've tested is: In the Webhook's template, if I extract, for example, the
MessageId
like this:
"messageId": "{{ body.MessageId }}"
There is no issue. This works fine. But if I try to extract something from inside the
Message
of the body using something like this:
"file_name": "{{ body.Message.Records[0].s3.object.key }}"
Nothing happens, file_name ends up being empty. I thought that maybe the whole
Message
was being parsed as a single string so I did this just to test:
"file_name": "{{ body.Message }}"
This made the Webhook fail with this error: "_unexpected character: line 8 column 23 (char 425)_" It seems like I just cannot access
Message
, not even as a string(?) Does anyone understand this issue and know how to extract the value I'm trying to obtain? Thanks for the help!
b
The
message
field is a string, so trying to do
Records[0].s3.object.key
will fail.
@Andres Mora are you required to use SNS?
For reference, our S3 Bucket Sensor Terraform module uses AWS EventBridge to send payloads via webhook which allow for customization of the payload: https://github.com/PrefectHQ/terraform-prefect-bucket-sensor/blob/main/modules/s3/main.tf