2

I am unable to pass a variable in the tag-user cli command.

A=$(aws iam list-user-tags --user-name user --query 'Tags[].{Key:Key,Value:Value}' | grep -B2 "Description" | grep Value | awk -F ":" '{print $2}' | tr -d '",'| awk '$1=$1')
aws iam list-user-tags --user-name user --query 'Tags[].{Key:Key,Value:Value}' | grep -B2 "Description" | grep Value
        "Value": "Used for SSO",

A=Used for SSO

passing the value of A to the below CLI :

aws iam tag-user --user-name azure-sso-user --tags "[{"Key": "own:team","Value": "[email protected]"},{"Key": "security","Value": "Service"},{"Key": "comment","Value": "$A"}]"

This is the error I get:

Error parsing parameter '--tags': Invalid JSON:
[{Key: own:team,Value: [email protected]},{Key: security,Value: Service},{Key: own:comment,Value: Used
3
  • Is the value of A valid Json? Commented Nov 20, 2020 at 10:17
  • 1
    Also, pass --tags in double quotes but use single quotes for the actual keys and values. Commented Nov 20, 2020 at 10:31
  • @RamanSailopal I find your way better than approved answer. Thanks. Commented Jan 13, 2023 at 9:57

1 Answer 1

1

This worked:

aws iam tag-user --user-name user --tags '[{"Key": "own:team","Value": "[email protected]"},{"Key": "security","Value": "Service"},{"Key": "own:comment","Value": "'"$A"'"}]'

That is, using the following:

[
    {
        "Key": "own:team",
        "Value": "[email protected]"
    },
    {
        "Key": "security",
        "Value": "Service"
    },
    {
        "Key": "own:comment",
        "Value": "'"
        $A
        "'"
    }
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.