Last active
July 8, 2022 12:13
-
-
Save huksley/01b3d43194d1057a129befcd09766f9f to your computer and use it in GitHub Desktop.
Create AWS ECS cluster with CDK (short)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CdkStack extends Stack { | |
constructor(scope, id, hostname) { | |
super(scope, id, props); | |
const vpc = ec2.Vpc.fromLookup(this, "vpc", { vpcId: process.env.VPC_ID }); | |
const cluster = new ecs.Cluster(this, "cluster", { vpc, enableFargateCapacityProviders: true }); | |
const repository = ecr.Repository.fromRepositoryName(this, "images", image); | |
const lb = new patterns.ApplicationLoadBalancedFargateService(this, "service", { | |
cluster, | |
cpu: 1024, | |
desiredCount: 1, | |
memoryLimitMiB: 2048, | |
domainName: hostname, | |
domainZone: route53.HostedZone.fromHostedZoneAttributes(this, "zone", { | |
hostedZoneId: process.env.ZONE_ID, | |
zoneName: process.env.ZONE_NAME | |
}), | |
listenerPort: 443, | |
protocol: "HTTPS", | |
taskImageOptions: { | |
image: ecs.ContainerImage.fromEcrRepository(repository), | |
containerPort: 3000, | |
executionRole: taskRole, | |
taskRole, | |
logDriver: ecs.LogDrivers.awsLogs({ | |
mode: ecs.AwsLogDriverMode.NON_BLOCKING | |
}) | |
} | |
}); | |
lb.loadBalancer.addRedirect({ | |
sourcePort: 80, | |
sourceProtocol: "HTTP", | |
targetPort: 443, | |
targetProtocol: "HTTPS" | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the full version: https://gist.github.com/huksley/746665004649c3ed3536fc0bd12650ec