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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ dist-ssr
*.njsproj
*.sln
*.sw?
cdk.out/
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,11 @@ Combination of `cloudfront:setup` and `cloudfront:build:deploy` commands with or
### `serverless:remove`

Remove an entire stack configured in `serverless.yml` via CloudFormation.

## Deployment URLs

### S3 Website URL
http://javlonbek-shop-website.s3-website-ap-southeast-2.amazonaws.com

### CloudFront URL
Not available yet - AWS account verification pending (support ticket created)
11 changes: 11 additions & 0 deletions bin/cdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node
import * as cdk from 'aws-cdk-lib';
import { StaticWebsiteStack } from '../lib/static-website-stack';

const app = new cdk.App();
new StaticWebsiteStack(app, 'StaticWebsiteStack', {
env: {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: 'ap-southeast-2',
},
});
17 changes: 17 additions & 0 deletions cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"app": "npx ts-node --prefer-ts-exts bin/cdk.ts",
"watch": {
"include": ["**"],
"exclude": [
"README.md",
"cdk*.json",
"**/*.d.ts",
"**/*.js",
"node_modules",
"dist"
]
},
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true
}
}
39 changes: 39 additions & 0 deletions lib/static-website-stack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as cdk from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment';
import { Construct } from 'constructs';
import * as path from 'path';

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

// S3 bucket for static website
const websiteBucket = new s3.Bucket(this, 'WebsiteBucket', {
bucketName: 'javlonbek-shop-website',
removalPolicy: cdk.RemovalPolicy.DESTROY,
autoDeleteObjects: true,
websiteIndexDocument: 'index.html',
websiteErrorDocument: 'index.html',
publicReadAccess: true,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ACLS,
});

// Deploy website to S3
new s3deploy.BucketDeployment(this, 'DeployWebsite', {
sources: [s3deploy.Source.asset(path.join(__dirname, '../dist'))],
destinationBucket: websiteBucket,
});

// Outputs
new cdk.CfnOutput(this, 'S3WebsiteURL', {
value: websiteBucket.bucketWebsiteUrl,
description: 'S3 Website URL',
});

new cdk.CfnOutput(this, 'BucketName', {
value: websiteBucket.bucketName,
description: 'S3 Bucket Name',
});
}
}
Loading