You can use aws describeaws describe command to get all the ec2 instances that matches the tag with key="Instance"key="Instance" and value=["Trial1", "Trial2"]value=["Trial1", "Trial2"].
$ aws ec2 describe-instances --region <yourRegion> \
--query Reservations[*].Instances[*].[InstanceId] \
--filters "Name=tag:<tagKey>,Values=<tagValue>" --output text
The above command with provide you with instance id of instances matching the filter parameter. In next step you can pass the resource ids to below command.
$ aws ec2 create-tags --resources <id1> <id2> ... \
--tags 'Key=<tagKey>,Value=<newValue>'
Create-tagsCreate-tags command will create new tag if it doesn't exist. If it does then it will update the old tag value with new one.
Using xargsxargs you can combine both commands to a single line.
$ aws ec2 describe-instances --region <yourRegion> \
--query Reservations[*].Instances[*].[InstanceId] \
--filters "Name=tag:<tagKey>,Values=<tagValue>" \
--output text| xargs -n1 -I@ aws ec2 create-tags \
--resources @ --tags 'Key=<tagKey>,Value=<newValue>'
For more info:
https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html https://docs.aws.amazon.com/cli/latest/reference/ec2/create-tags.html
Hope it helps!!!