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) }

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ