a working deployment cdk

This commit is contained in:
Matthew Zhao
2021-03-03 17:26:49 -08:00
parent 9b1a240837
commit 1dd1969ac8
3 changed files with 42 additions and 6 deletions
+35 -4
View File
@@ -5,8 +5,11 @@ 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";
// tls certificate with ACM
import * as route53 from '@aws-cdk/aws-route53';
import * as acm from '@aws-cdk/aws-certificatemanager';
export class DeployStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
constructor(scope: cdk.Construct, id: string, hostedZoneID: string, domainName: string, props?: cdk.StackProps) {
super(scope, id, props);
// create vpc with 3 subnets
const vpc = new ec2.Vpc(this, "LocalTunnelVPC", {
@@ -16,18 +19,46 @@ export class DeployStack extends cdk.Stack {
const cluster = new ecs.Cluster(this, "LocalTunnelCluster", {
vpc: vpc
})
// create acm cert
const DNSZone = route53.HostedZone.fromHostedZoneAttributes(this, 'HostedZone', {
zoneName: domainName,
hostedZoneId: hostedZoneID
})
// add wildcard CNAME
new route53.CnameRecord(this, 'CnameRecordWildcard', {
zone: DNSZone,
recordName: "*",
domainName: domainName
})
const cert = new acm.Certificate(this, 'Cert', {
domainName: domainName,
subjectAlternativeNames: ["*."+domainName],
validation: acm.CertificateValidation.fromDns(DNSZone)
})
// create LBed Fargate service
new ecs_patterns.ApplicationLoadBalancedFargateService(this, "LocalTunnelService", {
let localtunnelsvc = 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
publicLoadBalancer: true,
certificate: cert,
redirectHTTP: true,
recordType: ecs_patterns.ApplicationLoadBalancedServiceRecordType.ALIAS,
listenerPort: 443,
domainName: domainName,
domainZone: DNSZone
})
// set health route
localtunnelsvc.targetGroup.configureHealthCheck({
path: "/api/status"
})
}
}