Going to AWS re:Invent 2024?

➡️ Book a meeting with Spacelift

Product

Introducing Notification Policies

Introducing Notification Policies

What are Notification Policies?

Notification policies in Spacelift allow you to create custom notifications that can be routed to the notification inbox, Slack, or webhooks to give you the information you need to manage your deployments. These policies are Space aware and apply to components in the same or inherited Spaces. You can also configure filters to ensure you only get the notifications you need and cut out the rest of the noise. 

what are notification policies

A Simple Notification Policy

Let’s take a look at a simple example of a notification policy.

This policy will send a notification to the notification inbox with a severity level of “info” every time a tracked run finishes. This notification will create a link to the run id to allow you to access the run information and see what happened in the run.

Also, notice the Space is the “root” Space. If you wish to allow all Spaces with inheritance enabled to be part of the notification policy, this is probably the Space in which you should save your policy. 

simple notification policy

The copyable version of the policy is here:

package spacelift

 inbox[{
  "title": "Tracked run finished!",
  "body": sprintf("http://saturnhead.app.spacelift.io/stack/%s/run/%s has finished", [stack.id, run.id]),
  "severity": "INFO",
 }] {
   stack := input.run_updated.stack
   run := input.run_updated.run
   run.type == "TRACKED"
   run.state == "FINISHED"
 }
 
 sample { true }

You can also modify this policy to work with Slack or a webhook. The parameters may be slightly different, but they are documented here and here. Once you save this policy, you should start seeing notifications in your notification inbox as soon as you have tracked runs in the finished state.

modify policy

Another Example

Let’s take a look at one more example that notifies on a tracked run failure. I’ll just paste the relevant policy code below:

package spacelift

 inbox[{
  "title": "Tracked run failed!",
  "body": sprintf("http://saturnhead.app.spacelift.io/stack/%s/run/%s has failed", [stack.id, run.id]),
  "severity": "ERROR",
 }] {
   stack := input.run_updated.stack
   run := input.run_updated.run
   run.type == "TRACKED"
   run.state == "FAILED"
 }
 
 sample { true }

As you can see, I have changed the “severity” to “ERROR”, the message to indicate the run has failed, and the run.state to “FAILED” instead of “FINISHED”. A pretty simple modification, and we now have notifications for all finished and failed runs.

notification on a tracked run failure

Perfect!

Check out this short video with the Notification Policy introduction:

Key Points

As you can see, the notification policy feature is extremely valuable and powerful when auditing and managing your infrastructure deployments. Much more information can be found in the documentation.

I hope you enjoy the new feature and keep deploying!

The most flexible management platform for Infrastructure as Code

Spacelift is a flexible orchestration solution for IaC development. It delivers enhanced collaboration, automation and controls to simplify and accelerate the provisioning of cloud based infrastructures.

Start free trial

The Practitioner’s Guide to Scaling Infrastructure as Code

Transform your IaC management to scale

securely, efficiently, and productively

into the future.

ebook global banner
Share your data and download the guide