Home

Awesome

Github - S3 Sync

If you have a static web site hosted in an S3 bucket, and you version control that site using Github, this script (and its associated GitHub / AWS configurations) will take new commits to your repo and sync them into your S3 bucket.

Overview

For new repositories, you should first set up the webooks, SNS queues, etc. before pushing any code. This will take your first commit and move all code into place. For existing repositories / s3 buckets, make sure your repo and your bucket are in sync before continuing.

Deployment

Note: special deep abiding thanks to this AWS Blog post, from which these instructions are adapted. I strongly recommend following that post's screenshots if this is unfamiliar territory.

Lambda IAM Role for Execution

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": "arn:aws:logs:*:*:*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "kms:Decrypt",
                "kms:DescribeKey",
                "kms:GetKeyPolicy"
            ],
            "Resource": "*"
        },
        {
        	"Effect": "Allow",
        	"Action": [
        	    "s3:GetObject",
        	    "s3:PutObject",
        	    "s3:DeleteObject"
        	],
        	"Resource": "arn:aws:s3:::your-bucket-name/"
    	}
    ]
}

S3 Permissions to allow storage / deletion

{
"Version": "2012-10-17",
"Id": "LambdaPermissions",
"Statement": [
	{
		"Sid": "AllowLambdaMgmt",
		"Effect": "Allow",
		"Principal": {
			"AWS": "arn:aws:iam::your-lambda-role-id-here"
		},
		"Action": [
			"s3:DeleteObject",
			"s3:GetObject",
			"s3:PutObject"
		],
		"Resource": "arn:aws:s3:::your-bucket-name/*"
	},
	{other permissions you may already have on this bucket}
	]
}

Warnings

To-do