Skip to content

Instantly share code, notes, and snippets.

View karen-kua's full-sized avatar

Karen Kua karen-kua

  • Toronto, Canada
View GitHub Profile
@karen-kua
karen-kua / index.js
Created June 14, 2020 21:30
AWS referer s3 bucket policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Allow get requests originating from example.com and *.example.com",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example.com/*",
"Condition": {
@karen-kua
karen-kua / bucketData.js
Last active September 28, 2022 02:31
S3 Bucket Custom Origin Data for Lambda@Edge Function
module.exports = [
{ product: "kimchibeanz", origin: "example-1.s3-website-us-east-1.amazonaws.com" },
{ product: "durianshakez", origin: "example-2.s3-website-us-east-1.amazonaws.com" },
{ product: "example", origin: "example-3.s3-website-us-east-1.amazonaws.com" }
// "example" is for when someone makes a request to https://example.com.
];
@karen-kua
karen-kua / index.js
Last active September 28, 2022 02:31
Lambda@Edge Function for Accessing React Apps in Sub-Directories of Multiple S3 Buckets
// Import the data that maps the origins to each product.
const bucketData = require("./bucketData.js");
exports.handler = (event, context, callback) => {
// Get the request object.
const request = event.Records[0].cf.request;
// Get the host from the request and take out "www." from the host if it exists.
let host = request.headers.host[0].value;
@karen-kua
karen-kua / index.js
Last active September 28, 2022 02:31
Lambda@Edge function for accessing React apps in different sub-directories
exports.handler = (event, context, callback) => {
// Get the request object.
const request = event.Records[0].cf.request;
// Get the host from the request and take out "www." from the host if it exists.
let host = request.headers.host[0].value;
host = host.replace(/^www\./, "");
// Check if the host contains a subdomain.