Create and Use Event Notifications
    • Dark
      Light

    Create and Use Event Notifications

    • Dark
      Light

    Article Summary

    The tutorials in this section guide you through creating Backblaze B2 Cloud Storage Event Notification rules and verifying signatures in notification messages. This guide uses Webhook.site and Pipedream to show the basics of setting up Event Notifications. It will also use AWS Lambda to create a simple integration that forwards notifications to an Amazon Simple Notification Service (SNS) topic or an Amazon Simple Queue Service (SQS) queue.

    Enable Event Notifications

    Note
    This feature is currently in private preview. For information about enabling this feature, see Automate Your Data Workflows With Backblaze B2 Event Notifications.

    Create an Event Notification Rule

    This procedure shows you how to create an event notification rule using Webhook.site as the endpoint. Webhook.site is an easy way to get a unique URL and view the messages that are sent to that URL.

    Before you begin, you must complete the following tasks:

    • Open a text file in the editor of your choice to save URLs and identifiers between the steps in this guide.
    • Navigate to Webhook.site in a new browser tab. Click the URL that appears in the field Your unique URL to copy it.
    • Save the URL in your editor, and leave the Webhook.site tab open. You will view Event Notifications on this site after you create the rules.
    • Sign in to your Backblaze account in another browser tab.
    • For the purposes of this tutorial, Backblaze recommends that you create a Backblaze B2 bucket or use an existing bucket.
    1. In the Backblaze web UI in the left navigation menu under B2 Cloud Storage, click Buckets and locate the bucket that you want to use for this process.
    2. Copy and save the bucket's ID and Endpoint values.
    3. Click Event Notifications, and click Add New Rule in the dialog.
    4. Enter a name for your rule.
      The name must be 6-63 characters in length and can contain only letters, digits, and "-."
    5. Select Object Created as the Event Category, and enable All Object Created Events so that notifications are sent when objects are created using any mechanism.
    6. Optionally, click Add Event Trigger to add Object Deleted and Hide Marker Created triggers.
    7. In the Target URL field, paste the Webhook.site URL that you copied earlier.
      Do not change the file path so that notifications are generated for all files, no matter their path. Do not enter values in the Custom HTTP Header fields.
    8. Optionally, enter a signing secret or click Generate Secret to automatically generate a signing secret.
      A signing secret must be 32 alphanumeric characters in length.
    9. Click Test Rule.
      A test message is sent to the Webhook.site endpoint, and a confirmation is displayed if no errors are found in your rule. If you see an error, ensure that the target URL is correct.
    10. Click Save Rule.

    Your new rule is displayed in the Event Notifications dialog.

    Verify the Event Notification Rule

    In your Webhook.site tab, the test message is displayed. The message has the same JSON structure as a “real” notification message, but it includes an event type of b2:TestEvent. The test message contains a signature in the x-bz-event-notification-signature HTTP header.

    Generate an Event Notification

    When you upload a file to your bucket, a notification appears in the Webhook.site site.

    The eventType is b2:ObjectCreated:Upload which indicates that the object was specifically created by uploading a file, rather than as a result of a server-side file copy or cloud replication. Metadata identifies your account, your bucket, the time that the event was triggered, the event notification rule, and the uploaded file (object).

    You can create additional rules for other event categories and observe the differences in the event notification messages as you hide and delete files.

    Next Steps

    If you complete either or both of the tutorials Trigger an Action from an Event Notification and Use AWS Lambda to Forward Event Notifications, then you should have a clear idea about how to validate the event notification message signature and parse the message content. You can also deploy an integration that matches one of your real-world use cases.


    Was this article helpful?