GithubHelp home page GithubHelp logo

aws-samples / amazon-cloudfront-keygroup-signed-url-sample Goto Github PK

View Code? Open in Web Editor NEW
3.0 4.0 2.0 619 KB

Sample for Amazon CloudFront signed urls using Key Groups and Public Keys

License: MIT No Attribution

HTML 0.75% JavaScript 39.45% TypeScript 59.80%
aws cloudfront keypair signed signed-url

amazon-cloudfront-keygroup-signed-url-sample's Introduction

Amazon CloudFront Key Group Signed URL Sample

This sample demonstrates how to create Amazon CloudFront signed urls using CloudFront Key Groups and CloudFront Public Keys.

Architecture

Architecture

  1. The admin user will invoke the rotate keys AWS Lambda when required.
  2. 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
  3. The generated private key PEM is stored in AWS Secrets Manager to be used later when signing URLs
  4. The generated public key PEM is stored as a CloudFront Public key. The CloudFront Key Group is also updated with the new Public key.
  5. The admin user will invoke the sign url AWS Lambda to generate a CloudFront signed url for each file required by the end user.
  6. The sign url AWS Lambda will request the current private key PEM file from AWS Secrets Manager
  7. The sign url AWS Lambda will get the current public key from the associated Amazon CloudFront distributions key group and sign the url
  8. The admin user will send the signed url to the user
  9. The user will access the signed url through Amazon CloudFront
  10. Amazon CloudFront validates the signed url and access the Amazon S3 bucket returning the results to the user

Requirements

  1. AWS Cloud Development Kit (CDK) 2.53.0 or higher
  2. AWS CLI for testing commands

Setup

  1. Git clone this repository
  2. From the root folder for this project run npm ci to install all packages required
  3. From the root folder for this project run cdk deploy to deploy

Running

  1. 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.
  2. The CloudFormation deployment will perform the initial key rotation by invoking RotateKeysLambdaInvokeCommand.
  3. 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.
  4. The second output RotateKeysLambdaInvokeCommand can run via your console to invoke the key rotation lambda.

Useful commands

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

Resource Cleanup

  1. From the root folder for this project run cdk destroy

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

amazon-cloudfront-keygroup-signed-url-sample's People

Contributors

amazon-auto avatar dependabot[bot] avatar swarwick avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.