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
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
Path to the script to execute
Type: string
- Script is executed in separate process.
- Only one of
executeScript
andexecuteCommand
can be configurted.
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
andexecuteCommand
can be configurted.
Environment variables passed to the command. (Doesn't work for function-based hooks).
Type: Array of EnvironmentVar
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:deployexecuteCommand: npx next buildresources:nextJsApp:type: container-workloadproperties:containers:- name: next-js-serverimageConfig:filePath: src/next-server.tsincludeFiles:- 'public/**/*'...
Execute after deploy
In the following example, the hook executes a python script after each deployment.
hooks:- triggers:- after:deployexecuteFunction: hooks/test-endpoints.pyresources:gateway:type: http-api-gateway...
API reference
Name of the environment variable
Type: string
Value of the environment variable
Type: (string or number or boolean)