Skip to content

Updating node instance tags from powershell script

0

I have ssm managed nodes, and for each node, I have a tag called app_version that records the current installed version of our inhouse application. To update our application, I am using a inhouse script to prepare our remote devices and then install the new version of software. What I would like to do is to automatically update the app_version tag from the script when the update is complete.

All I have done so far is find out what the instance ID is for each node (within the script). I assume that with the Instance-Id, I can send some AWS command to update the app_version tag to the new version number, but I cannot find relevant support documentation on how to do that.

echo "Update Instance tag..."
$jsonData = Get-Content 'C:\\ProgramData\\Amazon\\SSM\\runtimeconfig\\identity_config.json' | Out-String | ConvertFrom-Json
$instanceID=jsonData.InstanceId

This is as far as I have gotten.

Cheers

3 Answers
0

Hello.

If you want to change the tags of an EC2 instance, how about using the AWS CLI's "create-tags" command?
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/create-tags.html

I think you can edit the tag if you can execute the following command within EC2.

aws ec2 create-tags --resources i-xxxxxxx --tags Key=app_version,Value=xxxx

By the way, in order to overwrite or create tags for EC2 instances, the action "ec2:CreateTags" must be allowed by the IAM role.
https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonec2.html

EXPERT
answered a year ago
EXPERT
reviewed a year ago
0

How about using Systems Manager Automation to run the script on the nodes and add a step to update the tags?

AWS
answered a year ago
  • That is one of the options that I looked at. However, Systems Manager Automation is not a simple beast, and I quickly looked for another solution. Automations, Runbooks, Documents, etc... All sounds good for AMI, but nothing is simple for edge devices.

    I'll give it another look though.

0

Unfortunately, our permissions will not allow the 'add-tags-to-resource', as allowing it opens up potential security risks. It can be called from any resource without restriction.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.