1.5.43 • Published 9 months ago

@liflig/cdk-cloudfront-auth v1.5.43

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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 @liflig/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.

1.5.43

9 months ago

1.5.42

10 months ago

1.5.41

11 months ago

1.5.30

11 months ago

1.5.32

11 months ago

1.5.31

11 months ago

1.5.34

11 months ago

1.5.33

11 months ago

1.5.36

11 months ago

1.5.35

11 months ago

1.5.38

11 months ago

1.5.37

11 months ago

1.5.39

11 months ago

1.5.40

11 months ago

1.5.29

11 months ago

1.5.28

11 months ago

1.5.27

11 months ago

1.5.26

11 months ago

1.5.25

11 months ago

1.5.24

11 months ago

1.5.23

11 months ago

1.5.22

11 months ago

1.5.21

11 months ago

1.5.20

11 months ago

1.5.19

11 months ago

1.5.18

11 months ago

1.5.17

11 months ago

1.5.16

11 months ago

1.5.15

11 months ago

1.5.14

11 months ago

1.5.13

11 months ago

1.5.12

11 months ago

1.5.11

11 months ago

1.5.10

11 months ago

1.5.9

11 months ago

1.5.8

11 months ago

1.5.7

11 months ago

1.5.6

11 months ago

1.5.5

11 months ago

1.5.4

11 months ago

1.5.3

11 months ago

1.5.2

11 months ago

1.5.1

11 months ago

1.5.0

11 months ago

1.4.24

11 months ago

1.4.23

11 months ago

1.4.22

12 months ago

1.4.21

12 months ago

1.4.20

12 months ago

1.4.19

12 months ago

1.4.18

12 months ago

1.4.17

12 months ago

1.4.16

12 months ago

1.4.15

12 months ago

1.4.14

12 months ago

1.4.13

12 months ago

1.4.12

12 months ago

1.4.11

12 months ago

1.4.10

12 months ago

1.4.9

12 months ago

1.4.8

12 months ago

1.4.7

12 months ago

1.4.6

12 months ago

1.4.5

12 months ago

1.4.4

12 months ago

1.4.3

12 months ago

1.4.2

12 months ago

1.4.1

12 months ago

1.4.0

12 months ago

1.3.1

12 months ago

1.3.0

12 months ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago