Skip to content

UserNotes:lalyos

Lajos Papp edited this page Nov 21, 2016 · 2 revisions

my initial use-cases for cmd.io:

  • listing/filtering cloud resources (aws/gcloud/digitalocean ...)
  • one single instance list across all supported clouds (cost control)
  • sigil playground:
    • template from stdin (for example create a custom sigil from a PR branch, check before merging)
    • git push based template generation, no local sigil install needed

SSH setup

I like to type less (obviously you can create an alias as well), but ssh ControlMaster option will make all your cmd.io commands instant.

Create ssh config for cmd.io which reuses a "background" ssh connection

cat >> ~/.ssh/config <<EOF
Host cmd
    Hostname alpha.cmd.io
    User yourgithubname
    ControlMaster auto
    ControlPath /tmp/%r@%h:%p
    ControlPersist yes
EOF

List AWS resources

This is the most common use-case, so lets start implementing it with cmd.io. Simple aws-cli wrapping is fine, but lets take it a bit further:

  • cross region resource listing
  • configurable fields to display (to fit narrow terminal with most important data)
  • filtering based on Tags (you can rely your own internal tagging policies, like prod/test)

Ec2-list Command

install and configure the command

ssh cmd :add ec2-list lalyos/cmd-aws
ssh cmd ec2-list:config set \
  AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
  AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
  AWS_ROLE_ARN=$AWS_ROLE_ARN

Changing the fields

You can use the image locally as well, and tune the QUERY env var until you get it right:

QUERY='id: InstanceId, region: Placement.AvailabilityZone, started: LaunchTime, pubIp: PublicIpAddress'
docker run -it \
  -e AWS_ROLE_ARN=$AWS_ROLE_ARN \
  -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
  -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
  -e "QUERY=$QUERY" \
  lalyos/cmd-aws

Complex fields

awscli uses JMesPath for restricting fields, filtering/sorting arrays. But it uses all quotation marks: single, double even backtick. So if you want to pass a complicated awscli query parameter for example which includes space and backtick, you are entering the quotation hell. Or use QUERY_BASE64 which will be bas64 decoded in the containers entrypoint script.

QUERY='id: InstanceId, region: Placement.AvailabilityZone, started: LaunchTime, pubIp: PublicIpAddress, stack: join(``, Tags[?Key==`aws:cloudformation:stack-name`].Value || `[]`), name: join(``, Tags[?Key==`Name`].Value || `[]`), owner: join(``, Tags[?(Key==`owner` || Key==`Owner`)].Value || `[]`) '
QUERY='id: InstanceId, region: Placement.AvailabilityZone, started: LaunchTime, pubIp: PublicIpAddress,  name: join(``, Tags[?Key==`Name`].Value || `[]`)'
QUERY_BASE64=$(base64 <<< $QUERY)

docker run -it \
  -e AWS_ROLE_ARN=$AWS_ROLE_ARN \
  -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
  -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
  -e QUERY_BASE64=$(base64 <<< $QUERY) \
  lalyos/cmd-aws

Custom Docker Image

built by using: https://github.com/lalyos/docker-cmd-aws

Clone this wiki locally