- Newest
- Most votes
- Most comments
To print the value from a StringList parameter in an SSM Automation Document and assign it to a variable of type String, you can use the join filter in your Automation runbook. However, it seems there's a small issue in your current implementation.
In your SNS notification message, you're using:
Message: 'Stopping instance(s): {{ instanceId | join('', '') }}'
The join filter is being used incorrectly here. To properly join the elements of the StringList and convert it to a String, you should use:
Message: 'Stopping instance(s): {{ instanceId | join(', ') }}'
This will join the elements of the instanceId StringList with a comma and space separator.
For your specific case, where you want to display the instance IDs in the SNS notification, you can modify the Approve step as follows:
- name: Approve action: aws:approve nextStep: ChangeInstanceState isEnd: false inputs: NotificationArn: '{{ ApproverSnsTopicArn }}' Message: 'Stopping instance(s): {{ instanceId | join(', ') }}' Approvers: - '{{ Approver }}'
This should correctly display the instance IDs in your SNS notification message.
Also, make sure that when you're passing the instanceId parameter to your Automation execution, you're providing it as a proper StringList (comma-separated list of instance IDs).
If you need to use the joined string in other parts of your Automation document, you can create a variable to store it:
variables: instanceIdString: type: String default: '{{ instanceId | join(', ') }}'
Then you can reference this variable elsewhere in your document using {{ instanceIdString }}.
Remember that variables in Automation documents (schema version 0.3) can be updated during the execution, unlike parameters which remain static. This allows for more flexibility in handling and manipulating your data throughout the Automation workflow.
Sources
Data elements and parameters - AWS Systems Manager
Creating a Parameter Store parameter using Tools for Windows PowerShell - AWS Systems Manager
answered a year ago
Thank you for your query regarding StringList parameters in SSM Automation documents. The issue you're experiencing can be resolved with a small modification to your document. Here's the working solution:
schemaVersion: '0.3' description: Stops EC2 instance on approval assumeRole: arn:aws:iam::123456789:role/ssm-document-role parameters: instanceId: type: StringList description: The ID of the EC2 instance to stop ApproverSnsTopicArn: type: String description: Notification SNS ARN default: arn:aws:sns:us-east-1:123456789:automation-approval-topic Message: type: String description: Message for Approver Approver: type: String description: Approver ARN default: arn:aws:iam::123456789:user/ssm-approver mainSteps: - name: Approve action: aws:approve nextStep: ChangeInstanceState isEnd: false inputs: NotificationArn: '{{ ApproverSnsTopicArn }}' Message: 'Stopping instance(s): {{ instanceId | join(", ") }}' Approvers: - '{{ Approver }}' - name: ChangeInstanceState action: aws:changeInstanceState isEnd: true inputs: DesiredState: stopped InstanceIds: '{{ instanceId }}'
The key changes are:
- In the
Messageinput, use the join function with{{ instanceId | join(", ") }}to properly format the instance IDs in the SNS notification - In the
ChangeInstanceStatestep, directly reference the StringList parameter withInstanceIds: '{{ instanceId }}'
This will ensure that:
- Your SNS notification displays the instance IDs correctly (e.g., "Stopping instance(s): i-1234567890, i-0987654321")
- The instance state change action receives the instance IDs in the correct format
Let me know if you need any clarification or have additional questions.
Relevant content
asked 2 years ago
asked 3 years ago

This approach is already tried and does not work. In fact it makes the runbook content invalid. AI is also confused about the SSM Parameter store here.