Built-in hooks

You can use hooks to execute actions at specific stages of stack deploy and undeploy operations. Takomo has one built-in hooks, and you can also implement your own.

In a stack configuration, you choose which type of hook to use by providing value to the type property. You also need to give a name for each hook. In addition to these two mandatory properties, each hook type may have its own set of additional properties.

Command hook

The command hook executes the specified shell command.

Properties

Here are the properties of the Command hook:

Key

Required

Type

Description

type

yes

string

Type of the hook, this must be cmd.

name

yes

string

Name of the hook.

command

yes

string

Shell command to execute.

cwd

no

string

The working directory from where the shell command is executed.

exposeStackCredentials

no

boolean

Make the current stack's AWS credentials available for the shell command. Defaults to false. Added in Takomo v3.5.0

exposeStackRegion

no

boolean

Make the current stack's region available for the shell command. Defaults to false. Added in Takomo v3.11.0.

capture

no

string

Controls how to capture the output of the executed shell command. By default, all output is captured. To capture only the last line, set this to last-line.

Environment variables available in the shell command

The following environment variables are available in the shell command:

Name

Description

TKM_COMMAND_STAGE

The current stack operation stage.

TKM_COMMAND_OPERATION

The current stack operation.

TKM_COMMAND_STATUS

The current stack operation status, not present in before stage

AWS_ACCESS_KEY_ID

If exposeStackCredentials is true, this will hold the access key id of credentials of the current stack.

AWS_SECRET_ACCESS_KEY

If exposeStackCredentials is true, this will hold the secret access key of credentials of the current stack.

AWS_SESSION_TOKEN

If exposeStackCredentials is true, this will hold the session token of credentials of the current stack.

AWS_SECURITY_TOKEN

If exposeStackCredentials is true, this will hold the session token of credentials of the current stack.

AWS_DEFAULT_REGION

IF exposeStackRegion is true, this will hold the region of the current stack.

Any output the hook prints to the stdout is captured and exposed for other hooks.

Examples

A command hook that runs a simple shell command:

- name: my-hook
command: echo 'hello world'

A command hook that exposes the current stack's AWS credentials to the shell command:

- name: my-another-hook
exposeStackCredentials: true
command: aws sts get-caller-identity

See also