arief-hidayat / my-cloudfront-functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Context

CloudFront functions for my own playground.

Please use at your own risk.

Deployment and test can either be via CLI or AWS Console. Scripts are untested.

Secure Token

CloudFront functions:

Prepare CloudFront Function

# set your key
export KEY_ID=your-key-id
export KEY=your-key
sed -i "s/YOUR_KEY_ID/${KEY_ID}/g" ./media_files_viewer_request.js
sed -i "s/YOUR_KEY/${KEY}/g" ./media_files_viewer_request.js

review TODO comment and make necessary change

Deployment

export CFF_NAME=media_files_viewer_request
./scripts/cff-create.sh

Test

Generate token using any of the following token generator

You can use CLI or AWS console to test

  • Go to AWS Console
  • Click the function. e.g. media_files_viewer_request
  • Click Test tab
  • Event type Viewer Request
  • Copy the URL path that was generated previously
  • Set headers based on what you use in the token generator, e.g. host, origin, referer, user-agent
  • Click Test Function

Publish

Once successful, you can click Publish tab and then Publish Function.

Alternatively using CLI.

./scripts/cff-publish.sh

Associate to your CloudFront distribution

  • Go to your CloudFront distributions
  • Click one CloudFront distribution
  • Click Behaviors tab
  • For each behavior that you want to associate this CF Function,
    • Select radio button and click Edit
    • Scroll down to Function associations section
    • On Viewer request,
      • Select CloudFront Function from Function type dropdown
      • Select this function name from Function ARN / Name dropdown
    • Click Save changes

After completely deployed, test your CloudFront distribution.

Clean up

./scripts/cff-delete.sh

About


Languages

Language:JavaScript 95.2%Language:Shell 4.8%