Repository: aws/aws-cli

Issue:
codecommit: tag-resource does not permit `:` character in tag key
The following command incorrectly returns an error even though colon characters (`:`) in tag keys are legal:

```
aws codecommit tag-resource --resource-arn <arn> --tags namespace:KeyName=value
```

Expected behavior: a new tag is applied to the resource with the name `namespace:KeyName` and value `value`.

Actual behavior:

```
Error parsing parameter '--tags': Expected: '=', received: ':' for input:
namespace:KeyName=value
```


Discussion:
@otterley - Thanks for posting this issue.  Try the following syntax:

```
aws codecommit tag-resource --resource-arn <arn> --tags Key=namespace:KeyName,Value=value
```

There are some other examples of tagging resources under the [EC2 reference page](https://docs.aws.amazon.com/cli/latest/reference/ec2/create-tags.html).

Let us know if this helps. 

Hi @justnance!  Codecommit's tagging API is different from EC2's, and so the `Key=k,Value=v` syntax is not used by the `tag-resource` subcommand or its corresponding API.  See [the CLI documentation](https://docs.aws.amazon.com/cli/latest/reference/codecommit/tag-resource.html) and [API documentation](https://docs.aws.amazon.com/codecommit/latest/APIReference/API_TagResource.html) for additional details.   

Using the syntax above, you would instead get two tags: one called `Key` whose value is `namespace:Keyname` and another called `Value` whose value is `value`. 
@otterley - Thanks for the feedback and sorry about recommending the wrong syntax.  I reproduced and used the following:

```
aws codecommit tag-resource --resource-arn arn:aws:codecommit:us-west-2:123456789101112:clitags --tags name="namespace:KeyName",Value=Value5
```
```
aws codecommit list-tags-for-resource --resource-arn arn:aws:codecommit:us-west-2:123456789101112:clitags
```

```json
{
    "tags": {
        "Value": "Value5",
        "name": "namespace:KeyName",
    }
}
```

I also found an example [here](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-tag-repository-add.html#how-to-tag-repository-add-cli) but I looks like some of our other documentation could use some better examples.  I'm going to get this escalated internally.  
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@otterley - As discussed offline, I am reopening this issue as I was able to reproduce and confirm this issue with the following steps:

1.  Created a new tag using the AWS Management Console which includes a colon and then listed it with the CLI:

```

$ aws codecommit list-tags-for-resource --resource-arn arn:aws:codecommit:us-west-2:1234567890101112:clitagtest
{
    "tags": {
        "namespace:Keyname": "namespaceValue"
    }
}

```

This confirmed the service was allowing a tag name with a colon.  Next, I tried to create another new tag with a colon using the following the CLI command but it returned the same error reported in your first response:

```
$ aws codecommit list-tags-for-resource --resource-arn arn:aws:codecommit:us-west-2:1234567890101112:clitagtest
{
    "tags": {
        "namespace:Keyname": "namespaceValue"
    }
}

$ aws codecommit tag-resource --resource-arn arn:aws:codecommit:us-west-2:123456789101112:clitagtest --tags "namespace:KeyName2"=KeyNameValue

Error parsing parameter '--tags': Expected: '=', received: ':' for input:
namespace:KeyName2=KeyNameValue

```

I am escalating this internally and we are looking to get it resolved. 
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

Hi, just confirming, shorthand syntax doesn't support `:` for key names.  Should be ok to update the parser to support this, but you'll have to use the JSON syntax for now to specify tag keys with `:`chars:


```
aws codecommit tag-resource --resource-arn aws:codeommit:us-east-1:12345:sfasfadsf \
    --tags '{"namespace:KeyName": "value"}'
```

Resolving patch:
diff --git a/awscli/shorthand.py b/awscli/shorthand.py
--- a/awscli/shorthand.py
+++ b/awscli/shorthand.py
@@ -163,7 +163,7 @@ def _keyval(self):
 
     def _key(self):
         # key = 1*(alpha / %x30-39 / %x5f / %x2e / %x23)  ; [a-zA-Z0-9\-_.#/]
-        valid_chars = string.ascii_letters + string.digits + '-_.#/'
+        valid_chars = string.ascii_letters + string.digits + '-_.#/:'
         start = self._index
         while not self._at_eof():
             if self._current() not in valid_chars:


Test patch:
diff --git a/tests/unit/test_shorthand.py b/tests/unit/test_shorthand.py
--- a/tests/unit/test_shorthand.py
+++ b/tests/unit/test_shorthand.py
@@ -62,6 +62,10 @@ def test_parse():
     # Forward slashes are allowed in keys.
     yield (_can_parse, 'some/thing=value', {'some/thing': 'value'})
 
+    # Colon chars are allowed in keys:
+    yield (_can_parse, 'aws:service:region:124:foo/bar=baz',
+           {'aws:service:region:124:foo/bar': 'baz'})
+
     # Explicit lists.
     yield (_can_parse, 'foo=[]', {'foo': []})
     yield (_can_parse, 'foo=[a]', {'foo': ['a']})