Skip to content

Instantly share code, notes, and snippets.

@lwoodson
Last active September 21, 2017 16:52
Show Gist options
  • Save lwoodson/d2a48551fe7ee44fb1fca87d028a42f9 to your computer and use it in GitHub Desktop.
Save lwoodson/d2a48551fe7ee44fb1fca87d028a42f9 to your computer and use it in GitHub Desktop.

For quickly iterating on ec2 instance bootstrapping without having to go through a cloudformation deployment cycle:

  1. Install sshfs or its mac port
  2. Deploy via cloudformation with minimal userdata script
  3. Mount the ec2-users home directory in your project (we will use a remote directory)
  4. Copy the ops code into the remote directory
  5. Edit files in the remote directory with your editor of choice set up as you have in your local env
  6. Test your changes by executing them as root from an ssh session on the remote host
  7. When things work to your liking, copy the ops code from the remote directory back to its location in your project
  8. Test bootstrapping via cloudformation stack deployment

One time set up for a service

If you want to have an easy way to do this in the future for a particular service (we'll call ours Petard), add the following to your ~/.bashrc or ~/.profile:

> export PETARD_KEY=...
> alias sshfs-petard='sshfs -o IdentityFile=${PETARD_KEY} ec2-user@${PETARD_HOST}:'

Mounting your ops code to the remote host

You will need the host name and private key for the ec2 instance you want to work with..

> export PETARD_HOST=....
> mkdir remote
> sshfs-petard remote
> cp -r ops/* remote

Editing your ops code on the remote host (install.sh example)

> cd remote
> vim install.sh
# or whatever editor you use

Testing your ops code on the remote host (install.sh example)

Assumes you've sshed in and have sudoed to root...

> cat /home/ec2-user/install.sh | bash -l

Keeping remote in synch with local

You could be rsynching, but not necessary with sshfs. Again, you will likely want to add this to your ~/.bashrc or ~/.profile:

> alias sshfs-sync='while true; do sleep ${DELAY:15}; cp ${REMOTE:=remote} ${LOCAL:=ops}; echo "Synched ${REMOTE} to ${LOCAL}"; done'

Removing the remote mount

# osx
> umount mountpoint

# linux
> fusermount -u mountpoint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment