Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.
Kevin Zhuang edited this page Jul 24, 2020 · 4 revisions

All EC2 related actions support alternate profile and region. You could either configure them through the fzfaws.yml config file or you could pass in command line options. The command line option take higher precedence and will override the config file settings.

fzfaws ec2 start --profile

Configure fzfaws.yml to set default profile and region for all EC2 actions, this will override the global settings of profile and region. In the example below, the default profile and us-east-1 will be used for all other services, but EC2 service will use the rootprofile profile and ap-southeast-2 by default.

global:
  profile: default
  region: us-east-1
services:
  ec2:
    keypair: ~/.ssh
    profile: rootprofile
    region: ap-southeast-2

SSH into instance

Reference individual option flag through the help manual fzfaws ec2 ssh -h.

The connection to all instances uses fall back, Public DNS -> Public IP -> Private IP.

Before running any commands below, make sure that you have followed the instructions here to inform fzfaws where your keypair/pem keys are located.

Alternatively, you could specify the path to the key.

fzfaws ec2 ssh --path ~/.ssh/keypair.pem

Connecting to an instance

By default, the user name to connect to an instance is set to ec2-user.

fzfaws ec2 ssh

Change the default user, maybe when connecting to an ubuntu machine.

fzfaws ec2 ssh --user ubuntu

Let's say in your aws environment, most machine is ubuntu, you could configure the fzfaws.yml config file to always have the --user ubuntu flag, and yet you could still override this setting if you want to switch to different user. Configure below in the relevant location in the config file.

services:
  ec2:
    keypair: ~/.ssh
    default_args:
      ssh: --user ubuntu

Tunnelling

fzfaws support 2 forms of tunneling. Under the hood, both are using the ssh -A flag to enable the ssh key forwarding. Hence before attempting to run any of it, make sure to add the key to ssh-agent.

ssh-add -K [Your key path]

Manual

Just like ssh, you could give fzfaws the -A flag to enable the key forwarding and then you can manually connect to other instance.

fzfaws ec2 ssh -A

Fuzzy select both

Using the -t or --tunnel flag will enable you select 2 instance. The first one being the jump box and the second one being the destination instance. You could specify a optional user name to connect to the second instance.

The connection to the second instance uses fall back, DNS -> public IP -> private IP.

# connect to the first instance using the user name cloud_user and the destination using ubuntu.
fzfaws ec2 ssh --user cloud_user --tunnel ubuntu

In the demo, the "default-ubuntu" only accepts connection through the security group associated with "default-playground" machine, we cannot directly connect to the ubuntu machine.

demo

Starting instances

Support multi selections, use TAB by default.

fzfaws ec2 start

You could optionally use the --wait flag to pause the program and wait for instance to be ready before exiting fzfaws.

fzfaws ec2 start --wait

demo

There is also the --check flag that will wait until the instance has 2/2 success status checks.

fzfaws ec2 start --check

The wait behavior is configured through fzfaws.yml waiter section, consult the default config file's comment for more details.

It is recommended to set --wait as the default args in the config file so you don't need to explicitly specify it, you can always stop the wait be hitting ctrl-c.

services:
  ec2:
    keypair: ~/.ssh
    waiter:
      delay: 10
      max_attempts: 60
    default_args:
      start: --wait
      stop: --wait
      terminate: --wait

Stopping instances

Support multi selections, use TAB by default.

fzfaws ec2 stop

If the instance support hibernate. Note: don't add --hibernate for no reason, fzfaws can't detect --hibernate failure.

fzfaws ec2 stop --hibernate

Terminating instances

Support multi selections, use TAB by default.

fzfaws ec2 terminate

Reboot instance

Support multi selections, use TAB by default.

fzfaws ec2 reboot

Listing EC2 information

Checkout the dedicated section for extending fzfaws functionalities which explains how and why for the ls commands.

The ls command will just print out information without doing any actions.

Consult the help manual to see the available options.

fzfaws ec2 ls --help
Clone this wiki locally