Last active
February 24, 2021 11:47
-
-
Save apoorvmote/9d6a5a43b83225d4842ef81165b5b1a8 to your computer and use it in GitHub Desktop.
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
/////////////////////////////// | |
// Part 5 | |
const hostedZone = HostedZone.fromHostedZoneAttributes(this, 'hostedZoneWithAttrs', { | |
hostedZoneId, | |
zoneName: website_domain | |
}) | |
new ARecord(this, 'aliasForCloudfront', { | |
target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)), | |
zone: hostedZone, | |
recordName: website_domain | |
}) | |
/////////////////////////////// |
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
version: 0.2 | |
phases: | |
install: | |
runtime-versions: | |
nodejs: 14.x | |
commands: | |
- echo Installing npm packages | |
- npm install | |
- npm update | |
build: | |
commands: | |
- echo Building react app | |
- npm run build | |
- echo Built react app on `date` | |
artifacts: | |
base-directory: ./build | |
files: | |
- '**/*' |
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
/////////////////////////////// | |
// Part 1 | |
const hostedZone = HostedZone.fromHostedZoneAttributes(this, 'HostedZoneWithAttrs', { | |
hostedZoneId, | |
zoneName: website_domain | |
}) | |
const websiteCert = new DnsValidatedCertificate(this, 'WebsiteSSL', { | |
domainName: website_domain, | |
hostedZone | |
}) | |
new CfnOutput(this, 'WebsiteCertArn', { | |
value: websiteCert.certificateArn | |
}) | |
/////////////////////////////// |
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
/////////////////////////////// | |
// Part 3 | |
const originAccessIdentity = new OriginAccessIdentity(this, 'originAccessIdentity', { | |
comment: 'Give cloudfront unrestricted read only access to website bucket' | |
}) | |
bucket.grantRead(originAccessIdentity) | |
/////////////////////////////// |
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
/////////////////////////////// | |
// Part 4 | |
const certificate = Certificate.fromCertificateArn(this, 'websiteCert', websiteCertArn) | |
const distribution = new CloudFrontWebDistribution(this, 'cloudfrontWebDistribution', { | |
priceClass: PriceClass.PRICE_CLASS_ALL, | |
originConfigs: [{ | |
s3OriginSource: { | |
s3BucketSource: bucket, | |
originAccessIdentity | |
}, | |
behaviors: [{ | |
isDefaultBehavior: true, | |
defaultTtl: Duration.hours(1) | |
}] | |
}], | |
viewerCertificate: ViewerCertificate.fromAcmCertificate(certificate, { | |
aliases: [website_domain], | |
securityPolicy: SecurityPolicyProtocol.TLS_V1_2_2019 | |
}) | |
}) | |
/////////////////////////////// |
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
/////////////////////////////// | |
// Part 2 | |
const bucket = new Bucket(this, 'websiteBucket', { | |
removalPolicy: RemovalPolicy.DESTROY, | |
bucketName: website_domain | |
}) | |
new CfnOutput(this, 'websiteBucketArn', { | |
value: bucket.bucketArn | |
}) | |
/////////////////////////////// |
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
/////////////////////////////// | |
// Part 7 | |
const websiteBucket = Bucket.fromBucketArn(this, 'websiteBucket', websiteBucketArn) | |
const reactBuildProject = new PipelineProject(this, 'reactBuild', { | |
buildSpec: BuildSpec.fromSourceFilename('buildspec.yml'), | |
environment: { | |
buildImage: LinuxBuildImage.STANDARD_5_0, | |
computeType: ComputeType.SMALL | |
} | |
}) | |
const artifactBucket = new Bucket(this, 'reactPipelineArtifactBucket', { | |
bucketName: 'react-pipeline-artifact-bucket', | |
removalPolicy: RemovalPolicy.DESTROY | |
}) | |
const gitOutput = new Artifact('reactRepoLatestMaster') | |
const buildOutput = new Artifact('reactBuildOutput') | |
new Pipeline(this, 'reactPipeline', { | |
artifactBucket, | |
pipelineName: 'examplePipeline', | |
stages: [ | |
{ | |
stageName: 'SourceCode', | |
actions: [ | |
new CodeCommitSourceAction({ | |
actionName: 'readLatestMasterCommit', | |
output: gitOutput, | |
repository: Repository.fromRepositoryArn(this, 'reactGitRepo', reactRepoArn) | |
}) | |
] | |
}, | |
{ | |
stageName: 'Build', | |
actions: [ | |
new CodeBuildAction({ | |
actionName: 'buildReactApp', | |
input: gitOutput, | |
outputs: [buildOutput], | |
project: reactBuildProject | |
}) | |
] | |
}, | |
{ | |
stageName: 'Deploy', | |
actions: [ | |
new S3DeployAction({ | |
actionName: 'DeployReactApp', | |
input: buildOutput, | |
bucket: websiteBucket | |
}) | |
] | |
} | |
] | |
}) | |
/////////////////////////////// |
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
/////////////////////////////// | |
// Part 6 | |
new HttpsRedirect(this, 'wwwToNonWww', { | |
recordNames: ['www.example.com'], | |
targetDomain: website_domain, | |
zone:hostedZone | |
}) | |
const repo = new Repository(this, 'reactSourceCode', { | |
repositoryName: 'example', | |
description: `react repo for ${website_domain}` | |
}) | |
new CfnOutput(this, 'reactRepoArn', { | |
value: repo.repositoryArn | |
}) | |
/////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment