GitHub Actions - Copy to S3 on Commit to Master

GitHub Actions can be for more than CI/CD. You can also use them to just simply publish to S3.

GitHub Actions

GitHub can trigger actions on events. This is what drives CI/CD integrations. But it can be used for things that are radically simpler too. I found myself wanting to automatically push changes to a CloudFormation (CF) template to an S3 bucket, since that’s where CF wants to pull templates from. But, as a software guy, I beleive in my soul of souls that everything is code, and code needs to be in source control - which means GitHub, for all practical purposes.

Secrets

First of all, you need to go into your repo settings and store your secrets:

Specifically you need to set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and if you want to just copy and paste from my main.yaml file you should set AWS_REGION. This is exactly the stuff from configuring AWS CLI tools. That’s the action you will be taking: using AWS CLI to sync files to an S3 bucket.

Actions

In your repo, you need to make a folder that tells GitHub what to do.

m t k o d u i c r h - . p g i . t g h i u t b h / u w b r w k o f r l k o f w l s o / w m s a i n . y a m l

In your favorite text editor, open .github/workflows/main.yaml and paste the following:

n o j a n o m : b b e s u : [ : i r s - - - p l u t C u d n e u n u w n r o s : s p s a s i a u p h - s e m e t a a a m n y ] o : s e s h w w w e : T n : : : : s s s : o : - - - a S a C a a s r C w 3 u c o w c e e o s b t n s c c g p u i f - e r i y s n o i a s e o 3 t n g c s t n T u s u t - - : e s - / r i k a m y l c e o e c $ p n a h n y c { l c t e A s - e { a e c W / i s t . s k S c d s s e t o o : - e s s u C n k c 3 t r f $ e r : @ e i { y e / v d g { : t / 1 e u s < n r s $ . y t e e { A o i - c { W u a a r S r l w e s _ - s s t e R b - s c E u c . r G c r A e I k e W t O e d S s N t e _ . - n A A } n t C W } a i C S m a E _ e l S S > s S E @ _ C v K R - 1 E E d Y T e _ _ l I A e D C t C e } E } S S _ K E Y } }

You can go peek at my working example for my bucket in S3.

Conclusion

This is so trivial and simple, but I had to go find a simple example because all the examples that are easily found are for much more complicated CI/CD behavior. I do owe a shout-out to a great example I found here for publishing a static web site.

Hope this helps someone!

Clicky

Clicky

 Share!