-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: hxtree <[email protected]>
- Loading branch information
Showing
50 changed files
with
528 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
#!/usr/bin/env node | ||
// TODO deploy to AWS | ||
// import * as cdk from 'aws-cdk-lib'; | ||
// import { AdminClientStack } from '../stacks/admin-client-stack'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { AdminClientStack } from '../stacks/admin-client.stack'; | ||
|
||
// const app = new cdk.App(); | ||
const app = new cdk.App(); | ||
|
||
// new AdminClientStack(app, 'AdminClientStack', {}); | ||
new AdminClientStack(app, 'AdminClientStack', {}); |
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
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,2 +1,121 @@ | ||
// TODO deploy to ec2 | ||
// https://nextjs.org/docs/pages/building-your-application/deploying | ||
import { Construct } from 'constructs'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as ssm from 'aws-cdk-lib/aws-ssm'; | ||
import { StackProps } from 'aws-cdk-lib'; | ||
import { Bucket, BucketAccessControl } from 'aws-cdk-lib/aws-s3'; | ||
import { BucketDeployment, Source } from 'aws-cdk-lib/aws-s3-deployment'; | ||
import { | ||
Distribution, | ||
OriginAccessIdentity, | ||
ResponseHeadersPolicy, | ||
} from 'aws-cdk-lib/aws-cloudfront'; | ||
import { S3Origin } from 'aws-cdk-lib/aws-cloudfront-origins'; | ||
import * as route53 from 'aws-cdk-lib/aws-route53'; | ||
import * as targets from 'aws-cdk-lib/aws-route53-targets'; | ||
import * as acm from 'aws-cdk-lib/aws-certificatemanager'; | ||
|
||
export class AdminClientStack extends cdk.Stack { | ||
public parentDomainName: string; | ||
public acmCertificateArn: string; | ||
public hostedZoneId: string; | ||
|
||
constructor(scope: Construct, id: string, props?: StackProps) { | ||
super(scope, id, props); | ||
|
||
// s3 bucket | ||
const bucket = new Bucket(this, 'Bucket', { | ||
accessControl: BucketAccessControl.PRIVATE, | ||
}); | ||
|
||
const originAccessIdentity = new OriginAccessIdentity( | ||
this, | ||
'OriginAccessIdentity', | ||
); | ||
bucket.grantRead(originAccessIdentity); | ||
|
||
this.acmCertificateArn = ssm.StringParameter.fromStringParameterAttributes( | ||
this, | ||
`${id}-orgformation-certs-wildcard-cert1-arn`, | ||
{ | ||
parameterName: 'orgformation-certs-wildcard-cert1-arn', | ||
}, | ||
).stringValue; | ||
|
||
const certificate = acm.Certificate.fromCertificateArn( | ||
this, | ||
`${id}-acm-certificate`, | ||
this.acmCertificateArn, | ||
); | ||
|
||
// DNS | ||
|
||
// fetch parameters from SSM Parameter Store | ||
this.parentDomainName = ssm.StringParameter.fromStringParameterAttributes( | ||
this, | ||
`${id}-ssm-domain-name`, | ||
{ | ||
parameterName: 'DOMAIN_NAME', | ||
}, | ||
).stringValue; | ||
|
||
// Retrieve parameters from SSM Parameter Store | ||
this.hostedZoneId = ssm.StringParameter.fromStringParameterAttributes( | ||
this, | ||
`${id}-hosted-zone-id`, | ||
{ | ||
parameterName: 'my-domains-hosted-zone-id', | ||
}, | ||
).stringValue; | ||
|
||
const subdomainName = 'admin'; | ||
|
||
const domainName = `${subdomainName}.${this.parentDomainName}`; | ||
|
||
// cloudfront distribution | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const cloudFrontDistribution = new Distribution(this, 'Distribution', { | ||
defaultRootObject: 'index.html', | ||
defaultBehavior: { | ||
origin: new S3Origin(bucket, { originAccessIdentity }), | ||
// todo lock down CORS later | ||
responseHeadersPolicy: | ||
ResponseHeadersPolicy.CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT, | ||
}, | ||
domainNames: [domainName], | ||
certificate, | ||
}); | ||
|
||
// bucket resource | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const awsBucketResource = new BucketDeployment(this, 'BucketDeployment', { | ||
destinationBucket: bucket, | ||
sources: [Source.asset('./dist')], | ||
}); | ||
|
||
const hostedZone = route53.PublicHostedZone.fromHostedZoneAttributes( | ||
this, | ||
`${id}-hosted-zone`, | ||
{ | ||
hostedZoneId: this.hostedZoneId, | ||
zoneName: domainName, | ||
}, | ||
); | ||
|
||
// Create a record set for the custom domain pointing to the CloudFront distribution | ||
new route53.ARecord(this, 'AliasRecord', { | ||
recordName: domainName, | ||
target: route53.RecordTarget.fromAlias( | ||
new targets.CloudFrontTarget(cloudFrontDistribution), | ||
), | ||
zone: hostedZone, | ||
}); | ||
|
||
new cdk.CfnOutput(this, 'Cloud Front Distribution', { | ||
value: cloudFrontDistribution.domainName, | ||
}); | ||
|
||
new cdk.CfnOutput(this, 'Domain Name', { | ||
value: `https://${domainName}`, | ||
}); | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. | ||
{ | ||
"pnpmShrinkwrapHash": "3a8692dbe1ed4ef82ded5abeca0fd8a82b8f6560", | ||
"pnpmShrinkwrapHash": "7ec5c1cd30817f579782876b74e76df4b257bf19", | ||
"preferredVersionsHash": "a48003cf229dd47d077bcf6301ac15a6f90e1c34" | ||
} |
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
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
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
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
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
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
Oops, something went wrong.