Skip to content

Instantly share code, notes, and snippets.

@flackjap
flackjap / cf-s3-access-policy.json
Created October 18, 2020 12:44
CloudFront Origin Access Bucket Policy
{
"Version": "2008-10-17",
"Id": "PolicyForCloudFrontPrivateContent",
"Statement": [
{
"Sid": "1",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity E336V70R8E3QKE"
},
@flackjap
flackjap / lambda-auth-cloudefront.js
Created October 18, 2020 11:13
AWS Lambda@Edge Basic Auth for CloudeFront in front of S3
'use strict';
exports.handler = (event, context, callback) => {
// Get request and request headers
const request = event.Records[0].cf.request;
const headers = request.headers;
// Configure authentication
const authUser = 'my-s3-username';
const authPass = 'my-s3-password';
@flackjap
flackjap / object-watch.js
Last active November 8, 2019 06:40 — forked from eligrey/object-watch.js
Fork of object.watch polyfill in ES5. Modified to not react when the value set is the same as previous.
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Public Domain.
*
* Modified by Nenad Damnjanović
* Nov 9, 2014