If the AWS Systems Manager public documents don't perform all the actions you want to perform on your AWS resources, you can create your own SSM documents. You can also clone SSM documents using the console. Cloning documents copies content from an existing document to a new document that you can modify. When creating or cloning a document, the content of the document must not exceed 64KB. This quota also includes the content specified for input parameters at runtime. When you create a new Command
or Policy
document, we recommend that you use schema version 2.2 or later so you can take advantage of the latest features, such as document editing, automatic versioning, sequencing, and more.
To create your own SSM document content, it's important to understand the different schemas, features, plugins, and syntax available for SSM documents. We recommend becoming familiar with the following resources.
AWS pre-defined SSM documents might perform some of the actions you require. You can call these documents by using the aws:runDocument
, aws:runCommand
, or aws:executeAutomation
plugins within your custom SSM document, depending on the document type. You can also copy portions of those documents into a custom SSM document, and edit the content to meet your requirements.
When creating SSM document content, you might change the content and update your SSM document several times while testing. The following commands update the SSM document with your latest content, and update the document's default version to the latest version of the document.
NoteThe Linux and Windows commands use the jq
command line tool to filter the JSON response data.
latestDocVersion=$(aws ssm update-document \
--content file://path
/to
/file
/documentContent
.json \
--name "ExampleDocument
" \
--document-format JSON \
--document-version '$LATEST' \
| jq -r '.DocumentDescription.LatestVersion')
aws ssm update-document-default-version \
--name "ExampleDocument
" \
--document-version $latestDocVersion
latestDocVersion=$(aws ssm update-document ^
--content file://C:\path
\to
\file
\documentContent
.json ^
--name "ExampleDocument
" ^
--document-format JSON ^
--document-version "$LATEST" ^
| jq -r '.DocumentDescription.LatestVersion')
aws ssm update-document-default-version ^
--name "ExampleDocument
" ^
--document-version $latestDocVersion
$content = Get-Content -Path "C:\path
\to
\file
\documentContent
.json" | Out-String
$latestDocVersion = Update-SSMDocument `
-Content $content `
-Name "ExampleDocument
" `
-DocumentFormat "JSON" `
-DocumentVersion '$LATEST' `
| Select-Object -ExpandProperty LatestVersion
Update-SSMDocumentDefaultVersion `
-Name "ExampleDocument
" `
-DocumentVersion $latestDocVersion
When creating SSM documents, follow these security best practices to help prevent command injection and ensure secure parameter handling:
Use environment variable interpolation for string parameters that will be used in commands or scripts. Add the interpolationType
property with value ENV_VAR
to your string parameters:
{
"command": {
"type": "String",
"description": "Command to execute",
"interpolationType": "ENV_VAR"
}
}
You can further improve the security of your SSM documents by specifying that double-quote marks arenât accepted in values delivered by interpolation:
{
"command": {
"type": "String",
"description": "Command to execute",
"interpolationType": "ENV_VAR",
"allowedPattern": "^[^"]*$"
}
}
When using interpreted languages like Python, Ruby, or Node.js, reference parameters using the appropriate environment variable syntax:
# Python example
import os
command = os.environ['SSM_Message']
For backwards compatibility with older SSM Agent versions (prior to version 3.3.2746.0), include fallback logic for environment variables:
if [ -z "${SSM_command+x}" ]; then
export SSM_command="{{command}}"
fi
Combine environment variable interpolation with allowedPattern
for additional input validation. In the following example, the allowedPattern
value ^[^"]*$
specifically prevent double-quotes in the string value:
{
"command": {
"type": "String",
"interpolationType": "ENV_VAR",
"allowedPattern": "^[a-zA-Z0-9_-]+$"
}
}
Before implementing your SSM document, verify the following security considerations:
All string parameters that accept user input use environment variable interpolation when appropriate.
Input validation is implemented using allowedPattern
where possible.
The document includes appropriate error handling for parameter processing.
Backwards compatibility is maintained for environments using older SSM Agent versions.
For information about AWS service-owned resources that Systems Manager accesses and how to configure data perimeter policies, see Data perimeters in AWS Systems Manager.
Cloning an SSM documentYou can clone AWS Systems Manager documents using the Systems Manager Documents console to create SSM documents. Cloning SSM documents copies content from an existing document to a new document that you can modify. You can't clone a document larger than 64KB.
To clone an SSM documentOpen the AWS Systems Manager console at https://console.aws.amazon.com/systems-manager/.
In the navigation pane, choose Documents.
In the search box, enter the name of the document you want to clone.
Choose the name of the document you want to clone, and then choose Clone document in the Actions dropdown.
Modify the document as you prefer, and then choose Create document to save the document.
After writing your SSM document content, you can use your content to create an SSM document using one of the following methods.
Creating composite documentsA composite AWS Systems Manager (SSM) document is a custom document that performs a series of actions by running one or more secondary SSM documents. Composite documents promote infrastructure as code by allowing you to create a standard set of SSM documents for common tasks such as boot-strapping software or domain-joining instances. You can then share these documents across AWS accounts in the same AWS Region to reduce SSM document maintenance and ensure consistency.
For example, you can create a composite document that performs the following actions:
Installs all patches in the allow list.
Installs antivirus software.
Downloads scripts from GitHub and runs them.
In this example, your custom SSM document includes the following plugins to perform these actions:
The aws:runDocument
plugin to run the AWS-RunPatchBaseline
document, which installs all allow listed patches.
The aws:runDocument
plugin to run the AWS-InstallApplication
document, which installs the antivirus software.
The aws:downloadContent
plugin to download scripts from GitHub and run them.
Composite and secondary documents can be stored in Systems Manager, GitHub (public and private repositories), or Amazon S3. Composite documents and secondary documents can be created in JSON or YAML.
NoteComposite documents can only run to a maximum depth of three documents. This means that a composite document can call a child document; and that child document can call one last document.
To create a composite document, add the aws:runDocument plugin in a custom SSM document and specify the required inputs. The following is an example of a composite document that performs the following actions:
Runs the aws:downloadContent plugin to download an SSM document from a GitHub public repository to a local directory called bootstrap. The SSM document is called StateManagerBootstrap.yml (a YAML document).
Runs the aws:runDocument
plugin to run the StateManagerBootstrap.yml document. No parameters are specified.
Runs the aws:runDocument
plugin to run the AWS-ConfigureDocker pre-defined
SSM document. The specified parameters install Docker on the instance.
{
"schemaVersion": "2.2",
"description": "My composite document for bootstrapping software and installing Docker.",
"parameters": {
},
"mainSteps": [
{
"action": "aws:downloadContent",
"name": "downloadContent",
"inputs": {
"sourceType": "GitHub",
"sourceInfo": "{\"owner\":\"TestUser1\",\"repository\":\"TestPublic\", \"path\":\"documents/bootstrap/StateManagerBootstrap.yml\"}",
"destinationPath": "bootstrap"
}
},
{
"action": "aws:runDocument",
"name": "runDocument",
"inputs": {
"documentType": "LocalPath",
"documentPath": "bootstrap",
"documentParameters": "{}"
}
},
{
"action": "aws:runDocument",
"name": "configureDocker",
"inputs": {
"documentType": "SSMDocument",
"documentPath": "AWS-ConfigureDocker",
"documentParameters": "{\"action\":\"Install\"}"
}
}
]
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4