Automatically Sync EC2 to S3

Blunt Jackson
2 min readDec 27, 2019

AWS Nomads #3: A quick win — a script to keep your Cloud9 / EC2 working directory in sync with your public S3 bucket.

They are smiling because their EC2 instances are in perfect harmony with their S3 buckets.

First of all, do not use this while working directly on a website that has traffic. You are going to save files, possibly accidentally, and they are going to be dropped into your public bucket instantly, and you are going to be making mistakes and breaking things.

If you don’t already have some form of staging system or development / production environment going for your live website, please consider that. (Note to self: future article.)

But while you are in the initial phase of rapid development or if you are syncing to a private staging environment that is not visible to the general public, this is a very pleasant and robust utility — and one that I have found many inferior or incomplete solutions for on StackOverflow and other blogs.

The gist of it (haha, yes the whole script is available in a gist, but also included below) is this:

  1. We give the local directory the same name as our s3 bucket.
  2. We run this script from the parent of our local directory with that bucket name.
  3. The script uses inotifywait to watch for changes on the developer box. EC2…

--

--

Blunt Jackson
Blunt Jackson

Written by Blunt Jackson

Building web applications since 1992. Crikey, that’s a long time.

No responses yet