aws / aws-cli

Universal Command Line Interface for Amazon Web Services
Other
15.53k stars 4.13k forks source link

Extend --generate-cli-skeleton to optionally generate pre-filled templates #6236

Open ScriptAutomate opened 3 years ago

ScriptAutomate commented 3 years ago

Is your feature request related to a problem? Please describe.

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug

I had followed the documentation for aws.ec2.delete-volume initially.

Running the following command deletes an EBS volume:

aws ec2 delete-volume --volume-id vol-049df61146c4d7901

Running the following, in prep for generating a yaml/json that can be consumed by [--cli-input-json | --cli-input-yaml] didn't do what I had expected:

# This is the equivelant of running
# aws ec2 delete-volume --generate-cli-skeleton
# because other args are ignored when --generate-cli-skeleton is present
$ aws ec2 delete-volume --volume-id vol-049df61146c4d7901 --generate-cli-skeleton
{
    "VolumeId": "",
    "DryRun": true
}

$ aws ec2 delete-volume --volume-id vol-049df61146c4d7901 --generate-cli-skeleton yaml-input
VolumeId: ''  # [REQUIRED] The ID of the volume.
DryRun: true # Checks whether you have the required permissions for the action, without actually making the request, and provides an error response.

$ aws ec2 delete-volume --volume-id vol-049df61146c4d7901 --generate-cli-skeleton output
# No output

It turns out I had misunderstood the functionality of --generate-cli-skeleton, and that is will ignore the other args you are providing (unless this is a bug):

--generate-cli-skeleton (string) Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input, prints a sample input JSON that can be used as an argument for --cli-input-json. Similarly, if provided yaml-input it will print a sample input YAML that can be used with --cli-input-yaml. If provided with the value output, it validates the command inputs and returns a sample output JSON for that command.

It doesn't create pre-populated templates based on the args used.

Describe the solution you'd like

It would be excellent if it worked this way:

# This is the equivelant of running
# aws ec2 delete-volume --generate-cli-skeleton
# because other args are ignored when --generate-cli-skeleton is present
$ aws ec2 delete-volume --volume-id vol-049df61146c4d7901 --generate-cli-skeleton
{
    "VolumeId": "vol-049df61146c4d7901",
    "DryRun": true
}

$ aws ec2 delete-volume --volume-id vol-049df61146c4d7901 --generate-cli-skeleton yaml-input
VolumeId: 'vol-049df61146c4d7901'  # [REQUIRED] The ID of the volume.
DryRun: true # Checks whether you have the required permissions for the action, without actually making the request, and provides an error response.

Describe alternatives you've considered

Provide some kind of error output or warning message that states other args have been ignored, or extend the documentation for --generate-cli-skeleton to be more clear about this current functionality.

stobrien89 commented 3 years ago

Hi @ScriptAutomate,

Thanks for the feature request! I'll review with the team to get their thoughts.

stobrien89 commented 3 years ago

Hi @ScriptAutomate,

Would you be able to elaborate further on your workflow/use-case for this? Thanks!

ScriptAutomate commented 3 years ago

Definitely, @stobrien89!

Workflow that would be possible if this feature exists:

$ aws ec2 delete-volume --volume-id vol-049df61146c4d7901 --generate-cli-skeleton yaml-input > delete-volume.yaml

Now I have the following in delete-volume.yaml:

VolumeId: 'vol-049df61146c4d7901'  # [REQUIRED] The ID of the volume.
DryRun: true # Checks whether you have the required permissions for the action, without actually making the request, and provides an error response.

Now I can later do something like this, without needing to fill the template out myself, to immediately test a DryRun of the template:

# This is DryRun by default, as shown in default template, and checks whether action can be done
$ aws ec2 delete-volume --cli-input-yaml delete-volume.yaml

I can then modify template to shift DryRun to false for when actually making use of the template, such as whether the action is a scheduled one to be done at a different time.

stobrien89 commented 3 years ago

Hi @ScriptAutomate,

Thanks for clarifying. I reviewed this with the team the other day and we agreed that it seems like a good/useful idea. We'll see how much traction this gets and take it from there!

arnelator commented 3 years ago

This looks like an error not a new feature? aws iam attach-group-policy --policy-arn arn:aws:iam::*:policy/orgs-assume-nnnnnn --group-name name_Orgs --generate-cli-skeleton output > temp.json got an empty file. https://docs.aws.amazon.com/cli/latest/reference/iam/attach-group-policy.html suggests otherwise. aws-cli/1.19.39

kdaily commented 3 years ago

Hi @arnelator,

You need to set --generate-cli-skeleton input:

aws iam attach-group-policy --generate-cli-skeleton input > temp.json

Note that providing other parameters does not stop the file from being generated, they just are not used (as suggested for this feature request).

hasan-dot commented 2 years ago

is this still valid? would be a great feature to have 🚀