This sample demonstrates how to create Amazon CloudFront signed urls using CloudFront Key Groups and CloudFront Public Keys.
- The admin user will invoke the rotate keys AWS Lambda when required.
- The rotate keys AWS Lambda will use the current symmetric key from AWS Key Management Service to call GenerateDataKeyPair which will be converted to PEM format
- The generated private key PEM is stored in AWS Secrets Manager to be used later when signing URLs
- The generated public key PEM is stored as a CloudFront Public key. The CloudFront Key Group is also updated with the new Public key.
- The admin user will invoke the sign url AWS Lambda to generate a CloudFront signed url for each file required by the end user.
- The sign url AWS Lambda will request the current private key PEM file from AWS Secrets Manager
- The sign url AWS Lambda will get the current public key from the associated Amazon CloudFront distributions key group and sign the url
- The admin user will send the signed url to the user
- The user will access the signed url through Amazon CloudFront
- Amazon CloudFront validates the signed url and access the Amazon S3 bucket returning the results to the user
- AWS Cloud Development Kit (CDK) 2.53.0 or higher
- AWS CLI for testing commands
- Git clone this repository
- From the root folder for this project run
npm ci
to install all packages required - From the root folder for this project run
cdk deploy
to deploy
- Once deployed the CloudFormation stack will create two outputs RotateKeysLambdaInvokeCommand and SignUrlLambdaInvokeCommand. These outputs are the cli commands to rotate the keys and to sign a url.
- The CloudFormation deployment will perform the initial key rotation by invoking RotateKeysLambdaInvokeCommand.
- To test the creation of a signed url please copy the SignUrlLambdaInvokeCommand cli command into your console and run. This command will produce an output with a signed url. Copy the signed url into your browser of choice to view the 'Hello World' example page via a signed url.
- The second output RotateKeysLambdaInvokeCommand can run via your console to invoke the key rotation lambda.
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template
- From the root folder for this project run
cdk destroy
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.