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.
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.cloudfront-functions/czldAPIRequest.js
: The CloudFront function to rewrite the s3 object key and add search terms as metadatacloudfront-functions/czldAPIResponse.js
: The CloudFront function to create a json response with the resulting urlcloudfront-functions/czldRedirect.js
: The CloudFront function extract the search terms from S3 metadata and redirect to Googlecloudfront-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.
npm install
If you've never used the CDK before, run:
npx cdk bootstrap
npx cdk deploy
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.
npx cdk destroy
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpx cdk deploy
deploy this stack to your default AWS account/regionnpx cdk diff
compare deployed stack with current statenpx cdk synth
emits the synthesized CloudFormation template