I want to run a few shell commands on an EC2 instance, so I came across the AWS Systems Manager Run Command, which uses a SSM document.
I am trying to create a command document, but I get an InvalidDocumentContent
error in the step name.
Here is the document:
{
"schemaVersion": "2.2",
"description": "Run svc-db-proxy Container",
"parameters": {
"AccessKeyID": {
"type": "String",
"description": "AWS Access Key ID"
},
"SecretAccessKey": {
"type": "String",
"description": "AWS Secret Access Key"
},
"AWSRegion": {
"type": "String",
"description": "AWS Region",
"default": "ca-central-1"
},
"Registry": {
"type": "String",
"description": "AWS ECR Registry URL"
},
"Repo": {
"type": "String",
"description": "AWS ECR Repository"
},
"Tag": {
"type": "String",
"description": "GitHub SHA used for Image tag"
}
},
"mainSteps": [
{
"action": "aws:runShellScript",
"name": "Deploy svc db proxy container",
"inputs": {
"timeoutSeconds": "3600",
"runCommand": [
"#!/bin/bash",
"export AWS_ACCESS_KEY_ID=\"{{AccessKeyID}}\"",
"export AWS_SECRET_ACCESS_KEY=\"{{SecretAccessKey}}\"",
"docker login -u AWS -p $(aws ecr get-login-password --region \"{{AWSRegion}}\") {{Registry}}",
"docker kill {{Repo}} || true",
"docker container prune -f || true",
"docker image prune -af || true",
"docker pull {{Registry}}/{{Repo}}:{{Tag}}",
"docker run --name {{Repo}} -p 8001:8000 -d {{Registry}}/{{Repo}}:{{Tag}}",
"docker logout {{Registry}}",
"unset \"AWS_ACCESS_KEY_ID\"",
"unset \"AWS_SECRET_ACCESS_KEY\""
]
}
}
]
}
The step name cannot include spaces.
As per the docs, the allowed regular expression pattern for name
is [a-zA-Z0-9_]+$
. This pattern excludes spaces.
Remove the spaces & it will pass validation e.g.
"name": "deploySvcContainer",