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 回答
2
已接受的回答

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
支持工程师
Aamir_H
已回答 2 个月前
profile picture
专家
已审核 2 个月前
  • 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) }

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则