aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

`--cli-input-json` does not support equals sign (`=`) when specifying argument

Open danfuzz opened this issue 3 years ago • 7 comments

Describe the bug

When passing JSON arguments via --cli-input-json, aws ec2 create-security-group seems to ignore the values GroupName and Description.

Expected Behavior

$ aws ec2 create-security-group --region=us-west-2 --cli-input-json='{"Description":"desc", "GroupName":"name", "VpcId":"vpc-xxxxxxxx"}'

{
    "GroupId": "sg-xxxxxxxx"
}

Current Behavior

$ aws ec2 create-security-group --region=us-west-2 --cli-input-json='{"Description":"desc", "GroupName":"name", "VpcId":"vpc-xxxxxxxx"}'

usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help

aws: error: the following arguments are required: --description, --group-name

Reproduction Steps

#/bin/bash

# Replace these with valid values.
region='us-west-2'
vpc='vpc-xxxxxxxx'

# Instead of using `jq` you can of course just write JSON directly.
args="$(jq -n --arg vpc "${vpc}" '{Description: "desc", GroupName: "name", VpcId: $vpc}')"

aws ec2 create-security-group --region="${region}" --cli-input-json="${args}"

Possible Solution

I assume there's something funky in the metadata or other command setup for create-security-group. Strangely though, the output of --generate-cli-skeleton seems to be what one would expect:

$ aws ec2 create-security-group --generate-cli-skeleton
{
    "Description": "",
    "GroupName": "",
    "VpcId": "",
    "TagSpecifications": [
        {
            "ResourceType": "transit-gateway-attachment",
            "Tags": [
                {
                    "Key": "",
                    "Value": ""
                }
            ]
        }
    ],
    "DryRun": true
}

Additional Information/Context

No response

CLI version used

aws-cli/2.6.1 Python/3.9.12 Darwin/21.5.0 source/arm64 prompt/off

Environment details (OS name and version, etc.)

macOS 12.4

danfuzz avatar Jun 22 '22 21:06 danfuzz

Hi @danfuzz,

Sorry to hear you're having trouble! I think your issue is subtle: remove the = signs from your command. This works for me:

aws ec2 create-security-group --region us-west-2 --cli-input-json '{"Description":"desc", "GroupName":"name", "VpcId":"vpc-xxxxxxxx"}'

kdaily avatar Jun 23 '22 21:06 kdaily

That's weird! I do --opt=value reflexively, and it seems to work in general with the AWS CLI. In fact, I've been working around this bug by adding --description=... and --group-name=...!

danfuzz avatar Jun 23 '22 22:06 danfuzz

Oh, and I should add, --cli-input-json=... — specifically — seems to work most of the time. In this case aws successfully pulled inVpcId from it.

danfuzz avatar Jun 23 '22 22:06 danfuzz

Just a quick note to confirm that changing --cli-input-json="..." to --cli-input-json "..." in my code gets rid of the failure. Happy to have a workaround, but still I remain super-curious what's causing the difference in behavior.

danfuzz avatar Jun 23 '22 23:06 danfuzz