Created
July 20, 2022 10:08
-
-
Save pauldambra/9af02d9ea42ffafcfc7c01dc38039958 to your computer and use it in GitHub Desktop.
A gist to create a cloudfront proxy for PostHog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as cdk from "aws-cdk-lib"; | |
import * as cloudfront from "aws-cdk-lib/aws-cloudfront"; | |
import * as cloudfront_origins from "aws-cdk-lib/aws-cloudfront-origins"; | |
import { Construct } from "constructs"; | |
// created by PostHog user CJ Enright | |
// shared in our community slack https://posthogusers.slack.com/archives/CTLTM70RM/p1657732914776719 | |
// many thanks to them ๐๐ | |
export class PostHogProxy extends cdk.Stack { | |
constructor(scope: Construct, id: string) { | |
super(scope, id); | |
const posthogPolicy = new cloudfront.OriginRequestPolicy( | |
this, | |
"PostHogProxyOriginRequestPolicy", | |
{ | |
queryStringBehavior: cloudfront.OriginRequestQueryStringBehavior.all(), | |
cookieBehavior: cloudfront.OriginRequestCookieBehavior.all(), | |
// Note you can also define which headers to pass through here (defaults | |
// to none), but passing all headers will NOT work: | |
// https://posthogusers.slack.com/archives/C01GLBKHKQT/p1653998887155389?thread_ts=1653991286.292179&cid=C01GLBKHKQT | |
}, | |
); | |
new cloudfront.Distribution(this, "PostHogProxyDistribution", { | |
defaultBehavior: { | |
origin: new cloudfront_origins.HttpOrigin("app.posthog.com"), | |
originRequestPolicy: posthogPolicy, | |
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL, | |
}, | |
priceClass: cloudfront.PriceClass.PRICE_CLASS_100, | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment