cdk for deploying stack with http

This commit is contained in:
Matthew Zhao
2021-03-02 22:57:49 -08:00
parent 78c06f8fc4
commit 9b1a240837
11 changed files with 14377 additions and 0 deletions

11
deploy/.gitignore vendored Normal file
View File

@@ -0,0 +1,11 @@
*.js
!jest.config.js
*.d.ts
node_modules
# CDK asset staging directory
.cdk.staging
cdk.out
# Parcel default cache directory
.parcel-cache

6
deploy/.npmignore Normal file
View File

@@ -0,0 +1,6 @@
*.ts
!*.d.ts
# CDK asset staging directory
.cdk.staging
cdk.out

14
deploy/README.md Normal file
View File

@@ -0,0 +1,14 @@
# Welcome to your CDK TypeScript project!
This is a blank project for TypeScript development with CDK.
The `cdk.json` file tells the CDK Toolkit how to execute your app.
## Useful commands
* `npm run build` compile typescript to js
* `npm run watch` watch for changes and compile
* `npm run test` perform the jest unit tests
* `cdk deploy` deploy this stack to your default AWS account/region
* `cdk diff` compare deployed stack with current state
* `cdk synth` emits the synthesized CloudFormation template

7
deploy/bin/deploy.ts Normal file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from '@aws-cdk/core';
import { DeployStack } from '../lib/deploy-stack';
const app = new cdk.App();
new DeployStack(app, 'DeployStack');

9
deploy/cdk.json Normal file
View File

@@ -0,0 +1,9 @@
{
"app": "npx ts-node --prefer-ts-exts bin/deploy.ts",
"context": {
"@aws-cdk/core:enableStackNameDuplicates": "true",
"aws-cdk:enableDiffNoFail": "true",
"@aws-cdk/core:stackRelativeExports": "true",
"@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true
}
}

7
deploy/jest.config.js Normal file
View File

@@ -0,0 +1,7 @@
module.exports = {
roots: ['<rootDir>/test'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
}
};

View File

@@ -0,0 +1,33 @@
import * as cdk from '@aws-cdk/core';
// import dependencies for ECS and building a VPC
import * as ec2 from "@aws-cdk/aws-ec2";
import * as ecs from "@aws-cdk/aws-ecs";
import * as ecs_patterns from "@aws-cdk/aws-ecs-patterns";
export class DeployStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// create vpc with 3 subnets
const vpc = new ec2.Vpc(this, "LocalTunnelVPC", {
maxAzs: 3
})
// create the ecs cluster
const cluster = new ecs.Cluster(this, "LocalTunnelCluster", {
vpc: vpc
})
// create LBed Fargate service
new ecs_patterns.ApplicationLoadBalancedFargateService(this, "LocalTunnelService", {
cluster: cluster,
cpu: 512,
desiredCount: 1,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("defunctzombie/localtunnel-server:latest")
},
memoryLimitMiB: 2048,
publicLoadBalancer : true,
assignPublicIp: true
})
}
}

14222
deploy/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

32
deploy/package.json Normal file
View File

@@ -0,0 +1,32 @@
{
"name": "deploy",
"version": "0.1.0",
"bin": {
"deploy": "bin/deploy.js"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk"
},
"devDependencies": {
"@aws-cdk/assert": "1.75.0",
"@types/jest": "^26.0.10",
"@types/node": "10.17.27",
"jest": "^26.4.2",
"ts-jest": "^26.2.0",
"aws-cdk": "1.75.0",
"ts-node": "^9.0.0",
"typescript": "~3.9.7"
},
"dependencies": {
"@aws-cdk/aws-certificatemanager": "^1.91.0",
"@aws-cdk/aws-ec2": "^1.91.0",
"@aws-cdk/aws-ecs": "^1.91.0",
"@aws-cdk/aws-ecs-patterns": "^1.91.0",
"@aws-cdk/aws-route53": "^1.91.0",
"@aws-cdk/core": "1.75.0",
"source-map-support": "^0.5.16"
}
}

View File

@@ -0,0 +1,13 @@
import { expect as expectCDK, matchTemplate, MatchStyle } from '@aws-cdk/assert';
import * as cdk from '@aws-cdk/core';
import * as Deploy from '../lib/deploy-stack';
test('Empty Stack', () => {
const app = new cdk.App();
// WHEN
const stack = new Deploy.DeployStack(app, 'MyTestStack');
// THEN
expectCDK(stack).to(matchTemplate({
"Resources": {}
}, MatchStyle.EXACT))
});

23
deploy/tsconfig.json Normal file
View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "ES2018",
"module": "commonjs",
"lib": ["es2018"],
"declaration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": false,
"inlineSourceMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"typeRoots": ["./node_modules/@types"]
},
"exclude": ["cdk.out"]
}