Skip to content

Instantly share code, notes, and snippets.

@natac13
natac13 / cf-template.yml
Created July 23, 2020 13:04
S3 301 redirect with headers set on metadata
AWSTemplateFormatVersion: "2010-09-09"
Description: "Static Website: server-side redirects with headers set on files found."
Metadata:
"AWS::CloudFormation::Interface":
ParameterGroups:
- Label:
default: "Required Parameters"
Parameters:
- DomainName
- Label:
@natac13
natac13 / cf-template.yml
Last active August 4, 2020 03:45
Gatsby Client Only Routes With AWS S3 CloudFront and Private bucket! Use a Lambda@Edge origin request
AWSTemplateFormatVersion: "2010-09-09"
Description: "Gatsby Static Website client only routes 'server-side' redirects."
Metadata:
"AWS::CloudFormation::Interface":
ParameterGroups:
- Label:
default: "Required Parameters"
Parameters:
- DomainName
- Label:
@natac13
natac13 / index-doc-filter.js
Last active May 26, 2020 15:49
Lambda request origin and response origin functions for serving S3 content with a private bucket using Cloudfront as a CDN
// Request origin Lambda@Edge function
// As shown in https://www.youtube.com/watch?v=pFean2aj_8I AWS Online Tech Talk
// Deploying JAMStack Applications Using S3, CloudFront and Lambda@Edge
exports.handler = async (event) => {
const request = event.Records[0].cf.request;
const uri = request.uri;
if(uri.endsWith('/')) {
request.uri += 'index.html';
} else if (!uri.includes('.')) {
@natac13
natac13 / insertHelpers.js
Created April 9, 2020 12:17
Mongoose graphql files
import R from 'ramda'
import mongoose from 'mongoose'
export function newObjectFromArgs(args, model, options) {
const fields = R.compose(
R.omit([]),
R.pathOr({}, ['schema', 'paths'])
)(model)
const newObject = R.reduce((acc, k) => {
// load the AWS SDK
const AWS = require('aws-sdk')
// load CloudFront key pair from environment variables
// Important: when storing your CloudFront private key as an environment variable string,
// you'll need to replace all line breaks with \n, like this:
// CF_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nMIIE...1Ar\nwLW...2eL\nFOu...k2E\n-----END RSA PRIVATE KEY-----"
const cloudfrontAccessKeyId = process.env.CF_ACCESS_KEY_ID
const cloudFrontPrivateKey = process.env.CF_PRIVATE_KEY
const signer = new AWS.CloudFront.Signer(cloudfrontAccessKeyId, cloudFrontPrivateKey)
@natac13
natac13 / a-mongodb-replica-set-docker-compose-readme.md
Created January 4, 2020 20:20 — forked from harveyconnor/a-mongodb-replica-set-docker-compose-readme.md
MongoDB Replica Set / docker-compose / mongoose transaction with persistent volume

This will guide you through setting up a replica set in a docker environment using.

  • Docker Compose
  • MongoDB Replica Sets
  • Mongoose
  • Mongoose Transactions

Thanks to https://gist.github.com/asoorm for helping with their docker-compose file!

Commit Message Guidelines

Short (72 chars or less) summary

More detailed explanatory text. Wrap it to 72 characters. The blank
line separating the summary from the body is critical (unless you omit
the body entirely).

Write your commit message in the imperative: "Fix bug" and not "Fixed
bug" or "Fixes bug." This convention matches up with commit messages
@natac13
natac13 / docker-compose.yml
Created August 14, 2019 10:21
MongoDB University M201 Docker setup
version: '2.4'
services:
db:
image: mongo:4.0.10-xenial
restart: 'always'
command: --wiredTigerCacheSizeGB 1 --auth --directoryperdb
volumes:
- dbData:/data/db
environment:
@natac13
natac13 / docker-compose.yml
Created August 13, 2019 13:58
A quick setup for Mongodb and importing data.
version: '2.4'
services:
db:
image: mongo:4.0.10-xenial
restart: 'always'
command: --wiredTigerCacheSizeGB 1 --auth --directoryperdb
volumes:
- dbData:/data/db
environment:
// a list of useful queries for profiler analysis. Starting with the most basic.
// 2.4 compatible
//
// output explained:
//
{
"ts" : ISODate("2012-09-14T16:34:00.010Z"), // date it occurred
"op" : "query", // the operation type
"ns" : "game.players", // the db and collection