Adding dynamic value to SSM node tag

0

Hello,

Ever since the Source ID was removed from the Run Command manual instance selection: Enter image description here I am having a hard time choosing the right instances.

However, I just discovered that the tag Name can be set and will show up in the columns, allowing for easy identification of the instance.

Is there a way to set the value of the tag Name to a dynamic value e.g. ${Computer Name} or something, so I can set up automatic naming in my Green Grass deployment configuration?

Best regards Lasse Bonner

1 Antwort
2
Akzeptierte Antwort

Yes, the "Name" tag value can be set dynamically.

Example:

I can see you are having Hybrid managed instances so as an example,

If you want to set Hostname of the instance as the Tag value, you can use below Shell or PowerShell scripts which will pull out the hostname and create a "Name" tag key with its value set as the hostname of the instance.

You can modify the script to set any value for the "Name" tag key instead of hostname and this can be pushed to multiple instances using "AWS-PowerShellScript" or "AWS-RunShellScript" document.

Linux:

instance=$(ssm-cli get-instance-information | jq -r '.["instance-id"]')
aws ssm add-tags-to-resource --resource-type "ManagedInstance" --resource-id $instance --tags Key=Name,Value=$(hostname)

Windows:

[System.Net.ServicePointManager]::SecurityProtocol = 'TLS12'
Install-Module -Name AWSPowerShell -Confirm:$false
Get-CimInstance -ClassName Win32_ComputerSystem
$hostname = (Get-CimInstance -ClassName Win32_ComputerSystem).Name
$path = & 'C:\Program Files\Amazon\SSM\ssm-cli.exe' get-instance-information
$instanceHostname = ($path | ConvertFrom-Json).'instance-id'
$tag = New-Object Amazon.SimpleSystemsManagement.Model.Tag
$tag.Key = "Name"
$tag.Value = '{0}' -F $hostname
Add-SSMResourceTag -ResourceType "ManagedInstance" -ResourceId $instanceHostname -Tag $tag -Force

Reference:

(-) https://docs.aws.amazon.com/systems-manager/latest/userguide/tagging-managed-instances.html

AWS
SUPPORT-TECHNIKER
Aamir_H
beantwortet vor 2 Monaten
profile picture
EXPERTE
überprüft vor 2 Monaten
  • Hi Aamir, thanks for the answer. Your solution makes sense to me, as a way to add the tags post creation. Do you know if there is some magic settings for greengrass component configuration that will always set the tag as above, but on creation. This is my current configuration I add to the aws.greengrass.SystemsManagerAgent on deployment.

    { "SSMRegistrationRole": "SSMServiceRole_****", "SSMResourceTags": [ { "Key": "project", "Value": "*****" } ], "SSMOverrideExistingRegistration": true }

    My greatest wish would be to be able to access the hostname in the the configuration above, like key: { "Key": "Name", "Value": $(hostname) }

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen