Exciting release!Introducing "safe npm". Learn more
Socket
Log inDemoInstall

@henrist/cdk-cloudfront-auth

Package Overview
Dependencies
2
Maintainers
1
Versions
135
Issues
File Explorer

Advanced tools

@henrist/cdk-cloudfront-auth

CDK Constructs for adding authentication for a CloudFront Distribution

    2.1.20latest
    GitHub

Version published
Maintainers
1
Weekly downloads
1,438
increased by3.45%

Weekly downloads

Changelog

Source

v2.1.20

2.1.20 (2023-03-19)

Bug Fixes

  • deps: update dependency webpack to v5.76.2 (dd572d3)

Readme

Source

CloudFront authorization with Cognito for CDK

Easily add Cognito-based authorization to your CloudFront distribution, to place static files behind authorization.

This is based on https://github.com/aws-samples/cloudfront-authorization-at-edge.

Usage

npm install @henrist/cdk-cloudfront-auth

Deploy the Lambda@Edge functions to us-east-1:

// In a stack deployed to us-east-1. const authLambdas = new AuthLambdas(this, "AuthLambdas", { regions: ["eu-west-1"], // Regions to make Lambda version params available. })

Deploy the Cognito and CloudFront setup in whatever region of your choice:

const auth = new CloudFrontAuth(this, "Auth", { cognitoAuthDomain: `${domain.domainName}.auth.${region}.amazoncognito.com`, authLambdas, // AuthLambdas from above userPool, // Cognito User Pool }) const distribution = new cloudfront.Distribution(this, "Distribution", { defaultBehavior: auth.createProtectedBehavior(origin), additionalBehaviors: auth.createAuthPagesBehaviors(origin), }) auth.updateClient("ClientUpdate", { signOutUrl: `https://${distribution.distributionDomainName}${auth.signOutRedirectTo}`, callbackUrl: `https://${distribution.distributionDomainName}${auth.callbackPath}`, })

If using CloudFrontWebDistribution instead of Distribution:

const distribution = new cloudfront.CloudFrontWebDistribution(this, "Distribution", { originConfigs: [ { behaviors: [ ...auth.authPages, { isDefaultBehavior: true, lambdaFunctionAssociations: auth.authFilters, }, ], }, ], })

Customizing authorization

The CloudFrontAuth construct accepts a requireGroupAnyOf property that causes access to be restricted to only users in specific groups.

Keywords

FAQs

Last updated on 19 Mar 2023

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc