wallix / awless

A Mighty CLI for AWS
http://awless.io/
Apache License 2.0
4.97k stars 263 forks source link

Providing extended execution on resources #168

Closed varunchandak closed 6 years ago

varunchandak commented 6 years ago

Currently, I have to use AWS CLI and awless in conjunction to meet certain requirements, such as creating an image from an ec2 instance. For a quickie, I use the following:

IFS=,
awless -p PROFILE -r REGION list instances \
    --filter name=NAME \
    --columns id,name \
    --format csv \
    --no-headers | while read INST_ID INST_NAME; do
        aws ec2 create-image \
            --profile PROFILE --region REGION  \
            --instance-id "$INST_ID" \
            --name "$INST_NAME-FINAL" \
            --reboot
    done
unset IFS

Can this be achieved something like this:

awless -p PROFILE -r REGION list instances \
    --filter name=NAME \
    --exec create image \
    --image-name "SOMETHING"

This can be extended to other resources such as security groups, volumes, etc, and also a good push towards more automation.

simcap commented 6 years ago

@varunchandak Indeed being able to bulk create/delete/... resources with awless is central to daily devops. As you show, it can be done with piping in conjunction with extra flag and there are some good ideas in there.

Although, the key issue for me here is that we overlooked the create image command ;) and I need to add it right now to awless!

In term of scripting bulk operations with awless we have on our roadmap the idea to use the templating language along with a query language to be more powerful, consistent, predictible and type safe.

simcap commented 6 years ago

@varunchandak Creating an image from an instance is now available from master. Help, documentation and params can be seen with awless create image -h.

As per your scenario, I created new images from my existing instances listing like so:

awless ls instances --columns name --format tsv --no-headers | xargs -I % awless create image instance=@% name=%-final -f

Important: First run it with only the listing of instances; then pipe in the other command but without the -f (i.e. force without prompting) flag! It will show you the template list it is going to run. Then full run with the -f flag.

Interesting points:

Let me know how that works for you in the case of instances.

varunchandak commented 6 years ago

Works Perfectly !

Unfortunately, the target instance went into reboot after firing that command. I think no-reboot should be made default. Guessing this was overlooked. Nevertheless the output looks good.

Waiting for this release.

simcap commented 6 years ago

Good! The reboot was not overlooked, I just kept the AWS default (as they suppose the user do not want to risk corruption with a running instance).

But I guess it makes sense and its more practical to have by default no reboot and specifying reboot=true when needed.

I will modify that.