forked from henrist/cdk-cloudfront-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from capralifecycle/cals-800/update-example-pro…
…ject Update and test example project
- Loading branch information
Showing
5 changed files
with
148 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
// import { AuthLambdas } from "@liflig/cdk-cloudfront-auth" | ||
// import * as cdk from "aws-cdk-lib" | ||
// import { Construct } from "constructs" | ||
// | ||
// export class AuthLambdasStack extends cdk.Stack { | ||
// readonly authLambdas: AuthLambdas | ||
// | ||
// constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
// super(scope, id, props) | ||
// | ||
// this.authLambdas = new AuthLambdas(this, "AuthLambdas", { | ||
// regions: ["eu-west-1"], | ||
// }) | ||
// } | ||
// } | ||
import { AuthLambdas } from "@liflig/cdk-cloudfront-auth" | ||
import * as cdk from "aws-cdk-lib" | ||
import { Construct } from "constructs" | ||
|
||
export class AuthLambdasStack extends cdk.Stack { | ||
readonly authLambdas: AuthLambdas | ||
|
||
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props) | ||
|
||
this.authLambdas = new AuthLambdas(this, "AuthLambdas", { | ||
regions: ["eu-west-1"], | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,81 @@ | ||
// import { AuthLambdas, CloudFrontAuth } from "@liflig/cdk-cloudfront-auth" | ||
// import * as cdk from "aws-cdk-lib" | ||
// import * as cloudfront from "aws-cdk-lib/aws-cloudfront" | ||
// import * as origins from "aws-cdk-lib/aws-cloudfront-origins" | ||
// import * as cognito from "aws-cdk-lib/aws-cognito" | ||
// import * as s3 from "aws-cdk-lib/aws-s3" | ||
// import * as s3Deployment from "aws-cdk-lib/aws-s3-deployment" | ||
// import * as constructs from "constructs" | ||
// import { CognitoUser } from "./cognito-user" | ||
// | ||
// interface Props extends cdk.StackProps { | ||
// authLambdas: AuthLambdas | ||
// } | ||
// | ||
// export class MainStack extends cdk.Stack { | ||
// constructor(scope: constructs.Construct, id: string, props: Props) { | ||
// super(scope, id, props) | ||
// | ||
// const bucket = new s3.Bucket(this, "Bucket") | ||
// | ||
// const userPool = new cognito.UserPool(this, "UserPool", { | ||
// signInAliases: { | ||
// email: true, | ||
// }, | ||
// passwordPolicy: { | ||
// minLength: 6, | ||
// requireSymbols: false, | ||
// requireUppercase: false, | ||
// }, | ||
// signInCaseSensitive: false, | ||
// }) | ||
// | ||
// const domainPrefix = `${this.account}-${this.stackName}` | ||
// | ||
// userPool.addDomain("UserPoolDomain", { | ||
// cognitoDomain: { | ||
// domainPrefix, | ||
// }, | ||
// }) | ||
// | ||
// const auth = new CloudFrontAuth(this, "Auth", { | ||
// cognitoAuthDomain: `${domainPrefix}.auth.${this.region}.amazoncognito.com`, | ||
// authLambdas: props.authLambdas, | ||
// userPool, | ||
// requireGroupAnyOf: ["test"], | ||
// }) | ||
// | ||
// const origin = new origins.S3Origin(bucket) | ||
// | ||
// const distribution = new cloudfront.Distribution(this, "Distribution", { | ||
// defaultBehavior: auth.createProtectedBehavior(origin), | ||
// additionalBehaviors: auth.createAuthPagesBehaviors(origin), | ||
// defaultRootObject: "index.html", | ||
// }) | ||
// | ||
// auth.updateClient("ClientUpdate", { | ||
// signOutUrl: `https://${distribution.distributionDomainName}${auth.signOutRedirectTo}`, | ||
// callbackUrl: `https://${distribution.distributionDomainName}${auth.callbackPath}`, | ||
// }) | ||
// | ||
// new s3Deployment.BucketDeployment(this, "BucketDeployment", { | ||
// sources: [s3Deployment.Source.asset("./website")], | ||
// destinationBucket: bucket, | ||
// distribution, | ||
// }) | ||
// | ||
// new CognitoUser(this, "User", { | ||
// userPool, | ||
// email: "[email protected]", | ||
// password: "example", | ||
// }) | ||
// | ||
// new cdk.CfnOutput(this, "UrlOutput", { | ||
// value: `https://${distribution.domainName}`, | ||
// }) | ||
// | ||
// new cdk.CfnOutput(this, "BucketNameOutput", { | ||
// value: bucket.bucketName, | ||
// }) | ||
// } | ||
// } | ||
import { AuthLambdas, CloudFrontAuth } from "@liflig/cdk-cloudfront-auth" | ||
import * as cdk from "aws-cdk-lib" | ||
import * as cloudfront from "aws-cdk-lib/aws-cloudfront" | ||
import * as origins from "aws-cdk-lib/aws-cloudfront-origins" | ||
import * as cognito from "aws-cdk-lib/aws-cognito" | ||
import * as s3 from "aws-cdk-lib/aws-s3" | ||
import * as s3Deployment from "aws-cdk-lib/aws-s3-deployment" | ||
import * as constructs from "constructs" | ||
import { CognitoUser } from "./cognito-user" | ||
|
||
interface Props extends cdk.StackProps { | ||
authLambdas: AuthLambdas | ||
} | ||
|
||
export class MainStack extends cdk.Stack { | ||
constructor(scope: constructs.Construct, id: string, props: Props) { | ||
super(scope, id, props) | ||
|
||
const bucket = new s3.Bucket(this, "Bucket") | ||
|
||
const userPool = new cognito.UserPool(this, "UserPool", { | ||
signInAliases: { | ||
email: true, | ||
}, | ||
passwordPolicy: { | ||
minLength: 6, | ||
requireSymbols: false, | ||
requireUppercase: false, | ||
}, | ||
signInCaseSensitive: false, | ||
}) | ||
|
||
const domainPrefix = `${this.account}-${this.stackName}` | ||
|
||
userPool.addDomain("UserPoolDomain", { | ||
cognitoDomain: { | ||
domainPrefix, | ||
}, | ||
}) | ||
|
||
const auth = new CloudFrontAuth(this, "Auth", { | ||
cognitoAuthDomain: `${domainPrefix}.auth.${this.region}.amazoncognito.com`, | ||
authLambdas: props.authLambdas, | ||
userPool, | ||
requireGroupAnyOf: ["test"], | ||
}) | ||
|
||
const origin = new origins.S3Origin(bucket) | ||
|
||
const distribution = new cloudfront.Distribution(this, "Distribution", { | ||
defaultBehavior: auth.createProtectedBehavior(origin), | ||
additionalBehaviors: auth.createAuthPagesBehaviors(origin), | ||
defaultRootObject: "index.html", | ||
}) | ||
|
||
auth.updateClient("ClientUpdate", { | ||
signOutUrl: `https://${distribution.distributionDomainName}${auth.signOutRedirectTo}`, | ||
callbackUrl: `https://${distribution.distributionDomainName}${auth.callbackPath}`, | ||
}) | ||
|
||
new s3Deployment.BucketDeployment(this, "BucketDeployment", { | ||
sources: [s3Deployment.Source.asset("./website")], | ||
destinationBucket: bucket, | ||
distribution, | ||
}) | ||
|
||
new CognitoUser(this, "User", { | ||
userPool, | ||
email: "[email protected]", | ||
password: "example", | ||
}) | ||
|
||
new cdk.CfnOutput(this, "UrlOutput", { | ||
value: `https://${distribution.domainName}`, | ||
}) | ||
|
||
new cdk.CfnOutput(this, "BucketNameOutput", { | ||
value: bucket.bucketName, | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters