Skip to content

dprosper/event-notifications-example

Repository files navigation

architecture

This repository is associated with the following blog post: https://www.ibm.com/blog/using-event-notifications-in-your-deployed-solutions/

Costs and Requirements

You must have a Pay-as-You-Go account in IBM Cloud™ to follow the steps in this repository to create resources. Since the costs for these resources will vary, use the Cost Estimator to generate a cost estimate based on your projected usage.

Make sure to delete services when they are no longer required in order to not incur charges in your account.

Getting Started as the Infrastructure Engineer

  1. Clone this repository to your local computer.
    git clone git@github.com:dprosper/event-notifications-example.git
  1. Copy or rename the .env.template an edit it to add your own values.
    cp .env.template .env
  1. Source the .env file to read the values into your environment.
    source .env
  1. Run Terraform init to download the required providers.
    terraform init
  1. Run Terraform to create and configure the environment.
    terraform apply
  1. As a result of running the apply, you will receive two email messages and two SMS messages asking you to confirm subscription to two topics. You must confirm the subscriptions for the two emails and the two SMS messages, i.e. a total of four confirmations.

The Event Notifications and Cloud Object Storage will be created and configured. A new file will be created in the directory called .apply.output.env and will be needed when you take the persona of the developer.

Continue as the Application Developer

  1. Login to IBM Cloud with your API Key, yes same key used for the infrastructure engineer, we are keeping things simple here ;-)
    ibmcloud login -r $TF_VAR_ibmcloud_region -g default --apikey $TF_VAR_ibmcloud_api_key
  1. Create a new Code Engine project.
    ibmcloud ce project create --name $TF_VAR_resources_prefix-project

TEST POINT #1: Shortly after having initiated that command, you will receive email and SMS messages notifying you that a new Code Engine project was created in your account. If you don't receive either or both, make sure you confirmed (accepted) the subscriptions. The Event Notifications UI can also be used for that. Navigate to the https://cloud.ibm.com/resources and expand the Developer tools section. Click on the Event Notifications instance and navigate to the Subscriptions section. Edit a subscription to view the Pending and Active invitations.

  1. Create a secret called apply-output based on the .apply.output.env that was created earlier after running the terraform apply.
  ibmcloud ce secret create --name apply-output --from-env-file .apply.output.env
  1. Deploy the application, we will use NodeJS (Go and Python are coming soon).
  ibmcloud ce app create --name node-app --src . --str buildpacks --build-context-dir /examples/app-nodejs/ --env-from-secret apply-output

If you need to update the app later on you can use the following command:

  ibmcloud ce app update --name node-app --src . --str buildpacks --build-context-dir /examples/app-nodejs/ --env-from-secret apply-output
  1. Access the NodeJS app serves an endpoint called /custom_notification, after you receive the URL to use for the application, try accessing that endpoint, i.e. https://<code-engine-app-url>/custom_notification. You should get a success message in the browser.

TEST POINT #2: Shortly after having access that endpoint, you can check the COS bucket that was created and you should find a new folder that contains the payload from the event.

cos-bucket

  1. Delete the Code Engine Project.
  ibmcloud ce project delete --name $TF_VAR_resources_prefix-project

TEST POINT #3: Shortly after having deleted the project, you will receive email and SMS messages notifying you that a Code Engine project was deleted in your account.

Wrapping up as the Infrastructure Engineer

  1. Run Terraform to delete the environment.
    terraform destroy

Issues

Please open issues here: New Issue

Related Content

License

See License for license information.