Use dynamic variables in your workflow document
You can use dynamic variables in your workflow documents to represent values
that vary at runtime for your image creation process. String interpolation for dynamic variables
allows you to embed JSONPath expressions within structured content such as JSON strings.This is
particularly useful when you need to pass runtime values within complex payloads to step actions
like ExecuteStateMachine or WaitForAction.
To use string interpolation for dynamic variables, wrap JSONPath expressions in double curly braces
"{{...}}" within your string content. Only JSONPath expressions wrapped in double curly braces are
processed as variables. Any JSONPath expressions not wrapped in double curly braces are
treated as literal string content.
JSONPath dynamic workflow variable syntax
$.<document structure>.[<step name>.]<variable name>
Dynamic variable values are represented as JSONPath selectors with structural nodes that uniquely
identify the target variable. The first node after the root ($) refers to the workflow document structure,
such as stepOutputs, or in the case of Image Builder system variables, imageBuilder.
The following list contains supported JSONPath workflow document structure nodes.
Document structure nodes
-
parameters - The workflow parameters
-
stepOutputs - Outputs from a step in the same workflow doc
-
workflowOutputs - Outputs from a workflow doc that already ran
-
imagebuilder - Image Builder system variables
The parameters and stepOutputs document structure nodes include
an optional node for the step name. This helps ensure unique variable names across all of
the steps.
The final node in the JSONPath is the name of the target variable, such as
instanceId.
Each step can refer to the output of any prior step actions with these JSONPath dynamic variables. This is also known as chaining, or referencing. To refer to output from a prior step action, you might use the following dynamic variable.
$.stepOutputs.step-name.output-name
Important
When an input parameter refers to a dynamic variable, the chaining indicator
(.$) must be attached to the end of the parameter name.
Example 1: Input parameter chaining indicator
The following example shows an input parameter that uses string interpolation to resolve a dynamic variable in the parameter value at runtime.
- name: ApplyTestComponents action: ExecuteComponents onFailure: Abort inputs: instanceId.$: "$.stepOutputs.LaunchTestInstance.instanceId"
Example 2: String interpolation in dynamic variables
The following example demonstrates how dynamic variables use string interpolation to determine values at runtime.
- name: ValidateImageConfiguration action: ExecuteStateMachine inputs: stateMachineArn: arn:aws:states:us-east-1:111122223333:stateMachine:ImageValidation input: | { "imageId": "{{ $.stepOutputs.CreateImageFromInstance.imageId }}", "region": "us-east-1", "buildDate": "{{ $.imagebuilder.dateTime }}", "instanceType": "{{ $.stepOutputs.LaunchStep.instanceType }}" }
In this example, the JSONPath expressions wrapped in double curly braces are resolved at runtime:
-
{{ $.stepOutputs.CreateImageFromInstance.imageId }}- Resolves to the actual image ID from the CreateImageFromInstance step -
{{ $.imagebuilder.dateTime }}- Resolves to the current build timestamp. See Use Image Builder system variables for a list of Image Builder system variables that you can use. -
{{ $.stepOutputs.LaunchStep.instanceType }}- Resolves to the instance type used in the LaunchStep
The literal strings like "region": "us-east-1" remain unchanged.
Note
String interpolation works with any string content in your workflow document,
including multiline strings using the YAML pipe (|) operator. The
curly brace requirement acts as an escape mechanism to clearly distinguish between
JSONPath variables and literal text content.
Use Image Builder system variables
Image Builder provides the following system variables that you can use in your workflow document:
|
Variable name |
Description |
Type |
Example value |
|---|---|---|---|
|
cloudWatchLogGroup |
The name of the CloudWatch Logs group for output logs. Format: |
String |
|
|
cloudWatchLogStream |
The name of the CloudWatch Logs stream for output logs. |
String |
|
|
collectImageMetadata |
The setting that directs Image Builder whether to collect instance metadata. |
Boolean |
|
|
collectImageScanFindings |
The current value of the setting that enables Image Builder to collect image scan findings. |
Boolean |
|
|
imageBuildNumber |
The build version number of the image. |
Integer |
|
|
imageId |
The AMI id of the base image. |
String |
|
|
imageName |
The name of the image. |
String |
|
|
imageType |
The image output type. |
String |
|
|
imageVersionNumber |
The version number of the image. |
String |
|
|
instanceProfileName |
The name of the instance profile role that Image Builder uses to launch build and test instances. |
String |
|
|
platform |
The operating system platform of the image that's built. |
String |
|
|
s3Logs |
A JSON object that contains configuration for the S3 logs that Image Builder writes. |
JSON object |
{'s3Logs': {'s3BucketName': ' |
|
securityGroups |
The security group IDs that apply to build and test instances. |
List [String] |
|
|
sourceImageARN |
The Amazon Resource Name (ARN) of the Image Builder image resource that the workflow uses for build and test stages. |
String |
arn:aws:imagebuilder: |
|
subnetId |
The ID of the subnet to launch the build and test instances into. |
String |
|
|
terminateInstanceOnFailure |
The current value of the setting that directs Image Builder to terminate the instance on failure or keep it for troubleshooting. |
Boolean |
|
|
workflowPhase |
The current stage that's running for the workflow execution. |
String |
|
|
workingDirectory |
The path to the working directory. |
String |
|