Skip to content

Conversation

@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented Jan 21, 2026

Summary

Add a deploy.after hook that runs after sst deploy completes. This is useful for:

  • Sending notifications (Slack, Discord, etc.)
  • Triggering follow-up actions
  • Logging deployment results

Changes

  • New hooks.go: Core hook execution logic with timeout support (default 30s, configurable via SST_HOOK_TIMEOUT)
  • UI integration: Hook start, complete, and error events are displayed in the CLI
  • TypeScript types: DeployResult, DeployError, DeployHooks, and Hooks interfaces
  • Documentation: JSDoc with examples in config.ts

Hook Result

The after hook receives a DeployResult object containing:

  • success — Whether the deployment completed without errors
  • errors — Array of errors if any occurred
  • outputs — The outputs from your run function
  • resources — Number of resources in the stack
  • app.name — The app name
  • app.stage — The stage name

Example

hooks: {
  deploy: {
    async after(result) {
      await fetch("https://example.com/webhook", {
        method: "POST",
        body: JSON.stringify({
          text: `Deployed ${result.app.name} to ${result.app.stage}`
        })
      });
    }
  }
}

Notes

  • Hook only runs after sst deploy, not during sst dev or sst diff
  • Hook errors will cause the deployment to fail
  • Hook will not run if deployment is interrupted (Ctrl+C)

Test plan

  • Deploy with a working hook and verify it runs after deployment
  • Deploy with a hook that throws an error and verify deployment fails
  • Deploy with a hook that uses try-catch and verify deployment succeeds
  • Verify hook does not run during sst dev or sst diff
  • Test timeout with SST_HOOK_TIMEOUT=5 and a slow hook

Add support for a `hooks.deploy.after` configuration in sst.config.ts that
runs after deployment completes. This enables users to send notifications,
trigger follow-up actions, or log deployment results.

Features:
- Hook receives DeployResult with success status, errors, outputs, and app info
- Configurable timeout via SST_HOOK_TIMEOUT env var (default 30s)
- Proper handling of cancellation and timeout with distinct error messages
- Hook errors are logged but don't fail the deployment
- UI displays hook start, completion, and error events

The hook only runs after `sst deploy`, not during `sst dev` or `sst diff`.
@michaelrambeau
Copy link

michaelrambeau commented Jan 21, 2026

A deploy hook would be a great improvement!

Maybe the configuration option to setup the hook should be mentioned in the documentation: https://sst.dev/docs/reference/config

Source: https://github.com/anomalyco/sst/blob/dev/platform/src/config.ts

@smorimoto
Copy link
Contributor Author

The documentation should probably be generated from the JSDoc of that file!

@vimtor vimtor self-assigned this Jan 22, 2026
@vimtor
Copy link
Collaborator

vimtor commented Jan 22, 2026

thanks for your contribution @smorimoto

this is a great change, probably it could replace #6177 as a more elegant solution.

a couple of thoughts:

  1. have you thought how this relates to the console.workflow config? in principle something similar to hooks could be implemented as a workflow. you need to use the sst console, though, so maybe it makes sense to uplift the workflow property to work outside the console?
  2. i believe hook errors should fail the deployment. someone will probably request it, so maybe failing the deployment is a better default. we can always let the user try-catch if they want that behaviour (similar to this workflow example)
  3. imagine you want to send a Slack message for the deployment. you'll need some API secret, right? how do you provide it? if i'm not mistaken, with the current setup you'll need to rely on env variables instead of SST secrets

Previously, hook errors were only logged and the deployment was considered
successful. Now hook errors will cause the deployment to fail, giving users
proper feedback when their post-deployment logic fails.

Users who want to handle errors gracefully can wrap their hook logic in a
try-catch block to prevent deployment failure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants