Simple commands which connects to AWS EC2 Instances!
You don't need to check your changed EC2 instance IP anymore. Just use 'ec2-connect'
ec2-ssh-autoconnect 의 속도를 개선한 Go 구현 버전입니다.
Features that this script provide is..
Download release binary. Currently, MacOS is only supported.
$ wget https://github.com/alicek106/go-ec2-ssh-autoconnect/releases/download/v0.7/ec2-connect-darwin && \ chmod +x ec2-connect-darwin && \ mv ec2-connect-darwin /usr/local/bin/ec2-connect
Create configuration file as /etc/ec2_connect_config.yaml like below.
version: v1 spec: region: "ap-northeast-2" # .spec.credentials is Optional. Instead you can define keys in ~/.aws/credentials credentials: accessKey: "... :D" secretKey: "... :D" privateKeys: - name: "default" # You should define default key path: "/Users/alicek106/dev/keys/DockerEngineTestInstance.pem" - name: "customKey1" # Optional. you can use this key as alternative path: "/Users/alicek106/dev/keys/VaultAdminKey.pem" instanceGroups: - name: "kubeadm_part" instances: ["kubeadm_master", "kubeadm_worker0"] - name: "kubeadm" instances: ["kubeadm_master", "kubeadm_worker0", "kubeadm_worker1", "kubeadm_worker2"] - name: "consul" instances: ["consul-1", "consul-2", "consul-3"] - name: "vault" instances: ["vault-1-active", "vault-2-standby"]
Configuration file consists of four part.
AWS credentials priority is like below.
FYI, I'm using third way (~/.aws/credentials) :D
Check EC2 instance list using ec2-connect list
$ ec2-connect list 2019/08/11 22:26:08 Cannot found credential in environment variable. 2019/08/11 22:26:08 Found credential in configuration file. 2019/08/11 22:26:09 Succeed to validate AWS credential. Instance ID Instance Name IP Address Status i-04f9e3da95a25e939 kubeadm-master Unknown stopped i-0c35c716a6442a72e kubeadm-worker0 Unknown stopped i-0ef65f12957a67559 kubeadm-worker2 Unknown stopped i-0c4bb55ba07c9edbf kubeadm-worker1 Unknown stopped i-0994dac6654fd59e1 Test 220.127.116.11 running
Start EC2 instance using ec2-connect start
$ ec2-connect start Test 2019/08/11 22:26:22 Cannot found credential in environment variable. 2019/08/11 22:26:22 Found credential in configuration file. 2019/08/11 22:26:22 Succeed to validate AWS credential. 2019/08/11 22:26:23 Starting EC2 instance : Test (instance ID: i-0994dac6654fd59e1) 2019/08/11 22:26:23 Succeed to start EC2 instances.
Connect to EC2 instance by ec2-connect connect [EC2 instance name]. This command uses private key defined in /etc/ec2_connect_config.yaml (spec.privateKeys)
$ ec2-connect connect Test 2019/08/11 22:26:54 Cannot found credential in environment variable. 2019/08/11 22:26:54 Found credential in configuration file. 2019/08/11 22:26:54 Succeed to validate AWS credential. 2019/08/11 22:26:55 Instance in active. Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-1088-aws x86_64) ... New release '18.04.2 LTS' available. Run 'do-release-upgrade' to upgrade to it. Last login: Sun Aug 11 13:15:12 2019 from 18.104.22.168 ubuntu@testbed:~$
Tip : If a instance is in STOP state, 'connect' command automatically start the instance and connect SSH. So you don't need to command 'start' actually. Just use connect!
Or, you can use user-defined key in ec2_connect_config.yaml by specifying --key. By default, this script uses "default" key in config file.
$ ec2-connect connect Test --key=MY_CUSTOM_KEY_PATH
Stop EC2 instance by ec2-connect stop [EC2 instance name]
$ ec2-connect stop Test 2019/08/11 22:28:12 Cannot found credential in environment variable. 2019/08/11 22:28:12 Found credential in configuration file. 2019/08/11 22:28:12 Succeed to validate AWS credential. 2019/08/11 22:28:12 Stoping EC2 instance : Test (instance ID: i-0994dac6654fd59e1) 2019/08/11 22:28:13 Succeed to stop EC2 instances.
If you defined custom group in /etc/ec2_connect_config.yaml, you can use 'group start' or 'group stop'
$ ec2-connect group start kubeadm_part 2019/08/11 22:29:07 Cannot found credential in environment variable. 2019/08/11 22:29:07 Found credential in configuration file. 2019/08/11 22:29:08 Succeed to validate AWS credential. 2019/08/11 22:29:08 Starting EC2 instance : kubeadm-master (instance ID: i-04f9e3d...) 2019/08/11 22:29:08 Starting EC2 instance : kubeadm-worker0 (instance ID: i-0c35c71...) 2019/08/11 22:29:08 Succeed to start EC2 instances. ...