# Hooks

Hooks are used to perform actions at different stages of stack deploy and undeploy commands.

# Basic Configuration

Hooks have the following properties:

  • name - Name of the hook
  • type - Type of the hook
  • operation - Operations during which the hook is executed
  • stage - Operation stages during which the hook is executed
  • status - Operation results during which the hook is executed

The name and type are required. The operation, stage and status are optional and used to control when the hook is executed.

The operation defines the type of stack operation during which the hook is executed. There are three supported operations:

  • create - The hook is executed when a new stack is created
  • update - The hook is executed when an existing stack is updated
  • delete - The hook is executed when an existing stack is deleted

The value can be given as a single value or a list of values. If no operation is defined, the hook is executed on all operations.

The stage defines the stage of command during which the hook is executed. There are two supported stages: before and after. The value can be given as a single value or a list of values. If no stage is defined, the hook is executed on all stages.

The status defines the result of command during which the hook is executed. There are four supported results: success, failed, skipped and cancelled. The value can be given as a single value or a list of values. If no status is defined, the hook is executed on all results.

In addition to the aforementioned properties, different hook types can have properties of their own.

Hooks are executed in the order they are defined. If a hook fails, the stack operation is aborted and deemed as failure.

Built-in hooks

There is one built-in hook:

See also

# Command hook

Executes the shell command given in the command property.

Any output the hook prints to the stdout can be captured and stored to a variable, and then referenced in the stack's CloudFormation template.

To create a command hook, set hook type to cmd.

Following information of the current command is exposed as environment variables:

Variable Description
TKM_COMMAND_STAGE The current command stage
TKM_COMMAND_OPERATION The current command operation
TKM_COMMAND_STATUS The current command status, not present in create stage

# Properties

Here are the properties for Command hook:

# type

  • Type: string
  • Required: yes
  • Default: undefined
  • Requirements:
    • Only cmd is accepted

Type of the hook.

# name

  • Type: string
  • Required: yes
  • Default: undefined
  • Requirements:
    • Must match regex /^[a-zA-Z0-9-_]+$/

Name of the hook.

# command

  • Type: string
  • Required: yes
  • Default: undefined
  • Requirements:
    • Must be a valid shell command

The shell command to execute.

# cwd

  • Type: string
  • Required: no
  • Default: Current project dir
  • Requirements:
    • Must be a valid dir path

The working directory.

Last Updated: 5/10/2020, 2:45:29 PM