2

I am working on AWS, where we have instances running SSM client. For automation, I am passing certain commands to these instances time-to-time. Currently, I have them setup with instance-id. This is proving inflexible for us, since any change to instance-id, will force me to update repository-code, and it's a hardcoded value.

How can I replace instance-id with tag:Name or similar.

Current code :

aws ssm send-command --instance-ids 'i-12434546' --region 'eu-central-1' --document-name 'AWS-RunShellScript' --comment 'Restart Pod' --parameters commands='sudo -u ubuntu kubectl rollout restart deployment.v1.apps/supplier-service-deployment' --output text

I want to replace

--instance-ids 'i-12434546'

With tag:Name. Any help would be nice. Thank you. :-)

We are Borg
  • 5,117
  • 17
  • 102
  • 225

1 Answers1

3

The answer to your question is provided directly on the documentation page (https://docs.aws.amazon.com/cli/latest/reference/ssm/send-command.html)

To target a larger number of instances, or if you prefer not to list individual instance IDs, we recommend using the Targets option instead. Using Targets , which accepts tag key-value pairs to identify the instances to send commands to, you can a send command to tens, hundreds, or thousands of instances at once.

You can use --targets option instead of --instance-ids:

aws ssm send-command \
--targets Key=tag:tag-name,Values=tag-value \
[...]
Michał Urbaniak
  • 1,249
  • 13
  • 28