logoStacktape docs




Hooks

Hooks allow to execution of custom commands or scripts before or after a specified Stacktape command is executed.

This enables users to "hook" into deploy, delete or other operations and perform custom actions before or after these actions.

Common cases for using hooks are:

  • Executing custom "build" command before each deploy
  • Executing custom validation script after each deploy
LifecycleHook  API reference
triggers
Required

List of events that will trigger this hook

Type: Array of string ENUM

Possible values: after:compile-templateafter:compile-template:errorafter:deleteafter:delete:errorafter:deployafter:deploy:errorafter:invoke-cloudafter:invoke-cloud:errorafter:invoke-localafter:invoke-local:errorafter:logsafter:logs:errorafter:package-workloadsafter:package-workloads:errorafter:preview-changesafter:preview-changes:errorafter:userpool-create-userafter:userpool-create-user:errorafter:userpool-get-tokenafter:userpool-get-token:errorbefore:compile-templatebefore:deletebefore:deploybefore:invoke-cloudbefore:invoke-localbefore:logsbefore:package-workloadsbefore:preview-changesbefore:userpool-create-userbefore:userpool-get-token

  • Format is {before or after}:{stacktape command}.
  • Example: before:deploy

executeScript

Path to the script to execute

Type: string

  • Script is executed in separate process.
  • Only one of executeScript and executeCommand can be configurted.

executeCommand

Terminal command to execute

Type: string

  • This command will be executed in the default shell.
  • Remember that if this command works on your machine, it doesn't mean it works for people or machines with different OSes or shells.
  • Only one of executeScript and executeCommand can be configurted.

cwd

Directory where the command will be executed. (Doesn't work for function-based hooks).

Type: string

Execute before deploy

In the following example, we are executing custom build command before each deploy

hooks:
- triggers:
- before:deploy
executeCommand: npx next build
resources:
nextJsApp:
type: container-workload
properties:
containers:
- name: next-js-server
imageConfig:
filePath: src/next-server.ts
includeFiles:
- 'public/**/*'
...

Execute after deploy

In the following example, the hook executes a python script after each deployment.

hooks:
- triggers:
- after:deploy
executeFunction: hooks/test-endpoints.py
resources:
gateway:
type: http-api-gateway
...

API reference

EnvironmentVar  API reference
Parent API reference: LifecycleHook
name
Required

Name of the environment variable

Type: string

value
Required

Value of the environment variable

Type: (string or number or boolean)