Skip to content

Using CloudFront as a lightweight proxy to create Google bookmarks with just CloudFront and S3

Notifications You must be signed in to change notification settings

perpil/coldstart-zero-loot-drop

Repository files navigation

CloudFront As a Lightweight Proxy

This is the companion repo for the blog post: Using CloudFront as a Lightweight Proxy The stack will create a Google Url Bookmark service that only uses CloudFront and S3.

Interesting files

  1. lib/searchurl-stack.ts - The CDK stack that creates the CloudFront distribution, CloudFront functions, OAC, S3 bucket and lifecycle policy to clean up the bucket.
  2. cloudfront-functions/czldAPIRequest.js: The CloudFront function to rewrite the s3 object key and add search terms as metadata
  3. cloudfront-functions/czldAPIResponse.js: The CloudFront function to create a json response with the resulting url
  4. cloudfront-functions/czldRedirect.js: The CloudFront function extract the search terms from S3 metadata and redirect to Google
  5. cloudfront-functions/czldPost.js: A CloudFront function unused in this stack, but that creates a presigned form to post to S3. Note If you use it, be sure to change the region I've hardcoded, put some credentials with the necessary permissions to write in KV Store and update the KV id as appropriate.

Setup

npm install

If you've never used the CDK before, run:

npx cdk bootstrap

Deploy

npx cdk deploy

Usage

Outputs will print a the url for the CloudFront distribution.

SearchUrlStack.Url = https://dxxxxxxxxxxxx.cloudfront.net

Enter your search terms and click Persist. The resulting url will load a file from S3 and redirect to Google with the search terms you originally entered.

Tearing it down

npx cdk destroy

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npx cdk deploy deploy this stack to your default AWS account/region
  • npx cdk diff compare deployed stack with current state
  • npx cdk synth emits the synthesized CloudFormation template

About

Using CloudFront as a lightweight proxy to create Google bookmarks with just CloudFront and S3

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published