Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ dist-ssr
*.njsproj
*.sln
*.sw?

cdk.out
4 changes: 4 additions & 0 deletions cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"app": "npx ts-node --prefer-ts-exts ./cdk/index.ts",
"context": {}
}
72 changes: 72 additions & 0 deletions cdk/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { Bucket } from 'aws-cdk-lib/aws-s3';
import {
Distribution,
OriginAccessIdentity,
ViewerProtocolPolicy,
} from "aws-cdk-lib/aws-cloudfront";
import * as S3Deployment from "aws-cdk-lib/aws-s3-deployment";
import { S3Origin } from "aws-cdk-lib/aws-cloudfront-origins";
import * as path from 'path';

const app = new cdk.App();

class CdkStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const websiteBucket = new Bucket(this, 'WebsiteBucket', {
bucketName: 'react-app-front-rs-app',
removalPolicy: cdk.RemovalPolicy.DESTROY,
autoDeleteObjects: true,
});

const originAccessIdentity = new OriginAccessIdentity(this, "OriginAccessIdentity");

websiteBucket.grantRead(originAccessIdentity);

const distribution = new Distribution(this, "ShopAppDistribution", {
defaultBehavior: {
origin: new S3Origin(websiteBucket, { originAccessIdentity }),
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
},
defaultRootObject: "index.html",
errorResponses: [
{
httpStatus: 404,
responseHttpStatus: 200,
responsePagePath: "/index.html",
},
],
});

new S3Deployment.BucketDeployment(this, "ShopAppDeployment", {
destinationBucket: websiteBucket,
sources: [S3Deployment.Source.asset(path.resolve(__dirname, '../dist'))],
distribution: distribution,
distributionPaths: ["/*"],
})

new cdk.CfnOutput(this, "cloudfrontUrl", {
value: distribution.distributionDomainName,
description: "The URL of the CloudFront distribution",
});
}
}

new CdkStack(app, 'CdkStack', {
/* If you don't specify 'env', this stack will be environment-agnostic.
* Account/Region-dependent features and context lookups will not work,
* but a single synthesized template can be deployed anywhere. */

/* Uncomment the next line to specialize this stack for the AWS Account
* and Region that are implied by the current CLI configuration. */
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },

/* Uncomment the next line if you know exactly what Account and Region you
* want to deploy the stack to. */
// env: { account: '123456789012', region: 'us-east-1' },

/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
});
7 changes: 7 additions & 0 deletions cdk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "CommonJS",
"noEmit": true,
},
}
Loading