Command custom stack is a built-in custom stack implementation that allows you to define shell commands to run at each phase of custom stack lifecycle, i.e. create, update and delete.
The Command custom stack is somewhat limited and not particularly easy to use, so in most cases you should implement your own custom stacks.
Here are the properties of the command custom stack.
All commands must output valid JSON string. Use capture property to control whether you want to use the whole script output or just the last line.
| Key | Required | Type | Description |
|---|---|---|---|
| createCommand | yes | string, Command Config | Shell command to execute when a new custom stack is created. Can be a plain string or complex object if more control is required. |
| updateCommand | yes | string, Command Config | Shell command to execute when an existing custom stack is updated. Can be a plain string or complex object if more control is required. |
| deleteCommand | no | string, Command Config | Shell command to execute when an existing custom stack is deleted. Can be a plain string or complex object if more control is required. |
| getCurrentStateCommand | no | string, Command Config | Shell command to execute when state of an existing custom stack is queried. Can be a plain string or complex object if more control is required. |
| getChangesCommand | no | string, Command Config | Shell command to execute when expected changes to an existing custom stack are queried. Can be a plain string or complex object if more control is required. |
| cwd | no | string | Path to the working directory from where the shell command is executed. Relative to the current project directory. Sets default value for all commands. |
| exposeStackCredentials | no | boolean | Make the current stack's AWS credentials available for the shell command. Defaults to false. Sets default value for all commands. |
| exposeStackRegion | no | boolean | Make the current stack's region available for the shell command. Defaults to false. Sets default value for all commands. |
| capture | no | boolean | 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. Sets default value for all commands. |
When configuring a shell command to execute with createCommand, updateCommand, deleteCommand, getCurrentStateCommand, and getChangesCommand, you can use a complex object instead of plain string.
| Key | Required | Type | Description |
|---|---|---|---|
| command | yes | string | Shell command to execute. |
| exposeStackCredentials | no | boolean | Make the current stack's AWS credentials available for the shell command. Defaults to false. |
| exposeStackRegion | no | boolean | Make the current stack's region available for the shell command. Defaults to false. |
| cwd | no | string | Path to the working directory from where the shell command is executed. Relative to the current project directory. |
| 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. |
The following environment variables are available in the shell commands:
| Name | Description |
|---|---|
| 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. |
| TKM_TAGS_JSON | Stack tags in JSON format. |
| TKM_TAG_<tag-name> | Each stack tag where the <tag-name> placeholder is replaced with the tag's name converted in uppercase and special characters replaced with underscore. |
| TKM_PARAMETERS_JSON | Stack parameters in JSON format. |
| TKM_PARAM_<param-name> | Each stack parameter where the <param-name> placeholder is replaced with the parameter's name converted in uppercase and special characters replaced with underscore. |
This is what happens when Takomo deploy command is executed:
getCurrentStateCommand command.getChangesCommand command.CREATE_COMPLETE or UPDATE_COMPLETE, the stack is updated by invoking updateCommand. Otherwise the stack will be created by invoking createCommand.This is what happens when Takomo undeploy command is executed:
getCurrentStateCommand command.CREATE_COMPLETE, UPDATE_COMPLETE or UNKNOWN, the stack is delete by invoking deleteCommand. Otherwise the stack delete is skipped.All commands must output valid JSON string. Use capture property to control whether you want to use the whole script output or just the last line.
This command is used to determine the current state of the custom stack.
The command must output valid JSON string representing CustomStackState.
Note that only status property is required, so the minimum state can look like this:
The status can be one of the following:
CREATE_COMPLETE = Stack existsUPDATE_COMPLETE = Stack existsPENDING = Stack does not existUNKNOWN = Stack status is unknownDuring deploy operation, this command is used to determine what changes the operation would apply to the custom stack.
The command must output valid JSON string representing an array of CustomStackChange objects.
You can return empty array if no changes are expected:
Or if there are changes, you can return:
There are no requirements for descriptions other than they should preferably be something informative.
During deploy operation, this command is used to create new custom stack resources.
The command must output valid JSON string representing CustomStackState.
Note that only status property is required, so the minimum state can look like this:
During deploy operation, this command is used to update existing custom stack resources.
The command must output valid JSON string representing CustomStackState.
Note that only status property is required, so the minimum state can look like this:
During undeploy operation, this command is used to delete existing custom stack resources.
The command output is ignored.
Simple usage of Command custom stack. Set customType: cmd to specify that you want to use Command custom stack.
Then, define configuration for the custom stack with customConfig property.
In this example, each command invokes a shell script that implements the actual logic. Properties exposeStackCredentials and exposeStackRegion
are set to true, so the shell script can access credentials and region of the current custom stack.