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.
CloudFront functions:
# 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
export CFF_NAME=media_files_viewer_request
./scripts/cff-create.sh
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
Once successful, you can click Publish
tab and then Publish Function
.
Alternatively using CLI.
./scripts/cff-publish.sh
- 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
fromFunction type
dropdown - Select this function name from
Function ARN / Name
dropdown
- Select
- Click
Save changes
- Select radio button and click
After completely deployed, test your CloudFront distribution.
./scripts/cff-delete.sh