Schemas, features, and examples
AWS Systems Manager (SSM) documents use the following schema versions.
-
Documents of type
Command
can use schema version 1.2, 2.0, and 2.2. If you use schema 1.2 documents, we recommend that you create documents that use schema version 2.2. -
Documents of type
Policy
must use schema version 2.0 or later. -
Documents of type
Automation
must use schema version 0.3. -
Documents of type
Session
must use schema version 1.0. -
You can create documents in JSON or YAML.
For more information about Session
document schema, see Session document schema.
By using the latest schema version for Command
and
Policy
documents, you can take advantage of the following
features.
Feature | Details |
---|---|
Document editing |
Documents can now be updated. With version 1.2, any update to a document required that you save it with a different name. |
Automatic versioning |
Any update to a document creates a new version. This isn't a schema version, but a version of the document. |
Default version |
If you have multiple versions of a document, you can specify which version is the default document. |
Sequencing |
Plugins or steps in a document run in the order that you specified. |
Cross-platform support |
Cross-platform support allows you to specify different
operating systems for different plugins within the same SSM
document. Cross-platform support uses the
|
Note
You must keep AWS Systems Manager SSM Agent on your instances updated with the latest version to use new Systems Manager features and SSM document features. For more information, see Updating the SSM Agent using Run Command.
The following table lists the differences between major schema versions.
Version 1.2 | Version 2.2 (latest version) | Details |
---|---|---|
runtimeConfig |
mainSteps |
In version 2.2, the |
properties |
inputs |
In version 2.2, the |
commands |
runCommand |
In version 2.2, the |
id |
action |
In version 2.2, |
not applicable |
name |
In version 2.2, |
Using the precondition parameter
With schema version 2.2 or later, you can use the precondition
parameter to specify the target operating system for each plugin or to validate
input parameters you've defined in your SSM document. The
precondition
parameter supports referencing your SSM
document's input parameters, and platformType
using values of
Linux
, MacOS
, and Windows
. Only the
StringEquals
operator is supported.
For documents that use schema version 2.2 or later, if precondition
isn't specified, each plugin is either run or skipped based on the plugin’s
compatibility with the operating system. Plugin compatibility with the operating
system is evaluated before the precondition
. For documents that use
schema 2.0 or earlier, incompatible plugins throw an error.
For example, in a schema version 2.2 document, if precondition
isn't
specified and the aws:runShellScript
plugin is listed, then the step
runs on Linux instances, but the system skips it on Windows Server instances because the
aws:runShellScript
isn't compatible with Windows Server instances.
However, for a schema version 2.0 document, if you specify the
aws:runShellScript
plugin, and then run the document on a Windows Server
instances, the execution fails. You can see an example of the precondition parameter
in an SSM document later in this section.
Schema version 2.2
Top-level elements
The following example shows the top-level elements of an SSM document using schema version 2.2.
Schema version 2.2 example
The following example uses the aws:runPowerShellScript
plugin
to run a PowerShell command on the target instances.
Schema version 2.2 precondition parameter examples
Schema version 2.2 provides cross-platform support. This means that within
a single SSM document you can specify different operating systems for
different plugins. Cross-platform support uses the precondition
parameter within a step, as shown in the following example. You can also use
the precondition
parameter to validate input parameters you've
defined in your SSM document. You can see this in the second of the
following examples.
Schema version 2.2 State Manager example
You can use the following SSM document with State Manager, a capability of Systems Manager, to download and install the ClamAV antivirus software. State Manager enforces a specific configuration, which means that each time the State Manager association is run, the system checks to see if the ClamAV software is installed. If not, State Manager reruns this document.
Schema version 2.2 Inventory example
You can use the following SSM document with State Manager to collect inventory metadata about your instances.
Schema version 2.2 AWS-ConfigureAWSPackage
example
The following example shows the AWS-ConfigureAWSPackage
document. The mainSteps
section includes the
aws:configurePackage
plugin in the action
step.
Note
On Linux operating systems, only the AmazonCloudWatchAgent
and AWSSupport-EC2Rescue
packages are supported.
Schema version 1.2
The following example shows the top-level elements of a schema version 1.2 document.
{ "schemaVersion":"1.2", "description":"
A description of the SSM document.
", "parameters":{ "parameter 1
":{ "one or more parameter properties
" }, "parameter 2
":{ "one or more parameter properties
" }, "parameter 3
":{ "one or more parameter properties
" } }, "runtimeConfig":{ "plugin 1
":{ "properties":[ { "one or more plugin properties
" } ] } } }
Schema version 1.2 aws:runShellScript
example
The following example shows the AWS-RunShellScript
SSM
document. The runtimeConfig section
includes the aws:runShellScript
plugin.
{ "schemaVersion":"1.2", "description":"Run a shell script or specify the commands to run.", "parameters":{ "commands":{ "type":"StringList", "description":"(Required) Specify a shell script or a command to run.", "minItems":1, "displayType":"textarea" }, "workingDirectory":{ "type":"String", "default":"", "description":"(Optional) The path to the working directory on your instance.", "maxChars":4096 }, "executionTimeout":{ "type":"String", "default":"3600", "description":"(Optional) The time in seconds for a command to complete before it is considered to have failed. Default is 3600 (1 hour). Maximum is 172800 (48 hours).", "allowedPattern":"([1-9][0-9]{0,3})|(1[0-9]{1,4})|(2[0-7][0-9]{1,3})|(28[0-7][0-9]{1,2})|(28800)" } }, "runtimeConfig":{ "aws:runShellScript":{ "properties":[ { "id":"0.aws:runShellScript", "runCommand":"{{ commands }}", "workingDirectory":"{{ workingDirectory }}", "timeoutSeconds":"{{ executionTimeout }}" } ] } } }
Schema version 0.3
Top-level elements
The following example shows the top-level elements of a schema version 0.3 Automation runbook in JSON format.
{ "description": "
document-description
", "schemaVersion": "0.3", "assumeRole": "{{assumeRole}}", "parameters": { "parameter1": { "type": "String", "description": "parameter-1-description
", "default": "" }, "parameter2": { "type": "String", "description": "parameter-2-description
", "default": "" } }, "variables": { "variable1": { "type": "StringMap", "description": "variable-1-description
", "default": {} }, "variable2": { "type": "String", "description": "variable-2-description
", "default": "default-value
" } }, "mainSteps": [ { "name": "myStepName
", "action": "action-name
", "maxAttempts": 1, "inputs": { "Handler": "python-only-handler-name
", "Runtime": "runtime-name
", "Attachment": "script-or-zip-name
" }, "outputs": { "Name": "output-name
", "Selector": "selector.value
", "Type": "data-type
" } } ], "files": { "script-or-zip-name
": { "checksums": { "sha256": "checksum
" }, "size":1234
} } }
YAML Automation runbook example
The following sample shows the contents of an Automation runbook, in YAML format. This working example of version 0.3 of the document schema also demonstrates the use of Markdown to format document descriptions.
description: >- ##Title: LaunchInstanceAndCheckState ----- **Purpose**: This Automation runbook first launches an EC2 instance using the AMI ID provided in the parameter ```imageId```. The second step of this document continuously checks the instance status check value for the launched instance until the status ```ok``` is returned. ##Parameters: ----- Name | Type | Description | Default Value ------------- | ------------- | ------------- | ------------- assumeRole | String | (Optional) The ARN of the role that allows Automation to perform the actions on your behalf. | - imageId | String | (Optional) The AMI ID to use for launching the instance. The default value uses the latest Amazon Linux AMI ID available. | {{ ssm:/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2 }} schemaVersion: '0.3' assumeRole: 'arn:aws:iam::111122223333::role/AutomationServiceRole' parameters: imageId: type: String default: '{{ ssm:/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2 }}' description: >- (Optional) The AMI ID to use for launching the instance. The default value uses the latest released Amazon Linux AMI ID. tagValue: type: String default: ' LaunchedBySsmAutomation' description: >- (Optional) The tag value to add to the instance. The default value is LaunchedBySsmAutomation. instanceType: type: String default: t2.micro description: >- (Optional) The instance type to use for the instance. The default value is t2.micro. mainSteps: - name: LaunchEc2Instance action: 'aws:executeScript' outputs: - Name: payload Selector: $.Payload Type: StringMap inputs: Runtime: python3.8 Handler: launch_instance Script: '' InputPayload: image_id: '{{ imageId }}' tag_value: '{{ tagValue }}' instance_type: '{{ instanceType }}' Attachment: launch.py description: >- **About This Step** This step first launches an EC2 instance using the ```aws:executeScript``` action and the provided python script. - name: WaitForInstanceStatusOk action: 'aws:executeScript' inputs: Runtime: python3.8 Handler: poll_instance Script: |- def poll_instance(events, context): import boto3 import time ec2 = boto3.client('ec2') instance_id = events['InstanceId'] print('[INFO] Waiting for instance status check to report ok', instance_id) instance_status = "null" while True: res = ec2.describe_instance_status(InstanceIds=[instance_id]) if len(res['InstanceStatuses']) == 0: print("Instance status information is not available yet") time.sleep(5) continue instance_status = res['InstanceStatuses'][0]['InstanceStatus']['Status'] print('[INFO] Polling to get status of the instance', instance_status) if instance_status == 'ok': break time.sleep(10) return {'Status': instance_status, 'InstanceId': instance_id} InputPayload: '{{ LaunchEc2Instance.payload }}' description: >- **About This Step** The python script continuously polls the instance status check value for the instance launched in Step 1 until the ```ok``` status is returned. files: launch.py: checksums: sha256: 18871b1311b295c43d0f...[truncated]...772da97b67e99d84d342ef4aEXAMPLE