IBM Cloud® Event Notifications is a service that can filter and route events received from other IBM Cloud services or custom applications to communication channels such as email, SMS, push notifications, webhook, Slack, Microsoft® Teams, ServiceNow, IBM Cloud Code Engine and IBM Cloud Object Storage.
This post explores how you can create and configure the Event Notifications service using an Infrastructure as Code (IaC) template (in this case, Terraform) and configure an example application to send custom events.
The Event Notifications instance is configured to enable lifecycle events and an API source to receive both platform events and events from a custom application that is to be deployed by the application developer.
The Terraform template enables the resource lifecycle events default source and adds 2 filters for when new instances are created and deleted from the cloud environment. These events are reported by the IBM Cloud Resource Controller:
The Terraform template creates a new API source for the custom application events. It then configures a destination and subscription to a newly created Cloud Object Storage bucket using the private COS endpoints:
The custom application requires a few pieces of information to be able to forward its events to the Event Notifications instance. The template generates these values at the end so they can be handed over to the developer.
instance_location
).instance_guid
).api_key
that is needed by the application to authenticate and pass events to the Event Notifications instance.api_source_name
and api_source_id
for the API source is provided.The application developer can include the values provided as environment variables to the application. They are used as shown below:
The payload in the event that is submitted is reduced since we know the subscriber going to this event will only go to a Cloud Object Storage bucket. Additional properties should be added based on the expected destination channel (learn more in the documentation).
I hope you will find this example useful in your own projects. To get started, review the README (link resides outside ibm.com) in the repository on GitHub for step-by-step instructions on how to deploy this example.
If you have feedback, suggestions or questions on this post, please reach out to me on LinkedIn (link resides outside ibm.com). You can also open GitHub issues (link resides outside ibm.com) on the related code samples for clarification.