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

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠