Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ coverage
dist
dist-ssr
*.local
cdk.out

# Editor directories and files
.vscode/*
Expand Down
41 changes: 6 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,9 @@
# React-shop-cloudfront
# Automated deploy

This is frontend starter project for nodejs-aws mentoring program. It uses the following technologies:
s3 -> http://my-bucket-automated.s3-website-eu-west-1.amazonaws.com/
cloudfront -> https://dear20x8infqh.cloudfront.net/

- [Vite](https://vitejs.dev/) as a project bundler
- [React](https://beta.reactjs.org/) as a frontend framework
- [React-router-dom](https://reactrouterdotcom.fly.dev/) as a routing library
- [MUI](https://mui.com/) as a UI framework
- [React-query](https://react-query-v3.tanstack.com/) as a data fetching library
- [Formik](https://formik.org/) as a form library
- [Yup](https://github.com/jquense/yup) as a validation schema
- [Vitest](https://vitest.dev/) as a test runner
- [MSW](https://mswjs.io/) as an API mocking library
- [Eslint](https://eslint.org/) as a code linting tool
- [Prettier](https://prettier.io/) as a code formatting tool
- [TypeScript](https://www.typescriptlang.org/) as a type checking tool
# Manual deploy

## Available Scripts

### `start`

Starts the project in dev mode with mocked API on local environment.

### `build`

Builds the project for production in `dist` folder.

### `preview`

Starts the project in production mode on local environment.

### `test`, `test:ui`, `test:coverage`

Runs tests in console, in browser or with coverage.

### `lint`, `prettier`

Runs linting and formatting for all files in `src` folder.
s3 -> http://rss-shop-app-bucket.s3-website-eu-west-1.amazonaws.com/
cloudfront -> https://d374j1fsl8eixz.cloudfront.net/
3 changes: 3 additions & 0 deletions cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "node index.mjs"
}
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<title>My shop</title>
</head>
<body>
<style>
* {
color: red;
}
</style>
<div id="app"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
Expand Down
65 changes: 65 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { aws_s3 as s3 } from "aws-cdk-lib";
import cloudfront from "aws-cdk-lib/aws-cloudfront";
import s3deploy from "aws-cdk-lib/aws-s3-deployment";
import iam from "aws-cdk-lib/aws-iam";
import { Construct } from "constructs";
import { App, Stack } from "aws-cdk-lib";

export class StaticSite extends Construct {
constructor(parent, name) {
super(parent, name);

const cloudfrontOAI = new cloudfront.OriginAccessIdentity(this, "OAI");

const siteBucket = new s3.Bucket(this, "MyBuckerAutomated", {
bucketName: "my-bucket-automated",
websiteIndexDocument: "index.html",
publicReadAccess: false,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
});

siteBucket.addToResourcePolicy(
new iam.PolicyStatement({
actions: ["S3:GetObject"],
resources: [siteBucket.arnForObjects("*")],
principals: [
new iam.CanonicalUserPrincipal(
cloudfrontOAI.cloudFrontOriginAccessIdentityS3CanonicalUserId
),
],
})
);

const distribution = new cloudfront.CloudFrontWebDistribution(
this,
"my-distribution-automated",
{
originConfigs: [
{
s3OriginSource: {
s3BucketSource: siteBucket,
originAccessIdentity: cloudfrontOAI,
},
behaviors: [
{
isDefaultBehavior: true,
},
],
},
],
}
);

new s3deploy.BucketDeployment(this, "My-Bucket-Deployment", {
sources: [s3deploy.Source.asset("./dist")],
destinationBucket: siteBucket,
distribution,
distributionPaths: ["/*"],
});
}
}

const app = new App();
const stack = new Stack(app, "MyStack");
new StaticSite(stack, "MyWebsite");
app.synth();
Loading