Last active
December 19, 2019 05:26
-
-
Save hirokihello/9df1248c7152b8c7bdce93e4578a2356 to your computer and use it in GitHub Desktop.
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
import ec2 = require('@aws-cdk/aws-ec2'); | |
import ecs = require('@aws-cdk/aws-ecs'); | |
import ecr = require('@aws-cdk/aws-ecr'); | |
import certmgr = require('@aws-cdk/aws-certificatemanager') | |
import route53 = require('@aws-cdk/aws-route53'); | |
import targets = require('@aws-cdk/aws-route53-targets'); | |
import ecs_patterns = require('@aws-cdk/aws-ecs-patterns'); | |
import cdk = require('@aws-cdk/core'); | |
export class CdkSampleStack extends cdk.Stack { | |
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { | |
super(scope, id, props); | |
const vpc = new ec2.Vpc(this, 'MyVpc', { maxAzs: 2 }); | |
const cluster = new ecs.Cluster(this, 'Cluster', { vpc }); | |
const fargateService = new ecs_patterns.ApplicationLoadBalancedFargateService(this, "fargateService", { | |
cluster, | |
memoryLimitMiB: 1024, | |
cpu: 512, | |
taskImageOptions: { | |
image: ecs.ContainerImage.fromEcrRepository(repository), | |
}, | |
}); | |
const zone = new route53.PublicHostedZone(this, 'HostedZone', { | |
zoneName: 'hirokihello.com' | |
}); | |
new route53.ARecord(this, 'AliasRecord', { | |
zone, | |
target: route53.RecordTarget.fromAlias(new targets.LoadBalancerTarget(fargateService.loadBalancer)), | |
// or - route53.RecordTarget.fromAlias(new alias.ApiGatewayDomainName(domainName)), | |
}); | |
const hostedZone = route53.HostedZone.fromLookup(this, 'CreatedHostedZone', { | |
domainName: 'hirokihello.com', | |
privateZone: false | |
}); | |
const certificate = new certmgr.DnsValidatedCertificate(this, 'TestCertificate', { | |
domainName: 'hirokihello.com', | |
hostedZone, | |
}); | |
const listener = fargateService.loadBalancer.addListener('Listener', | |
{ | |
port: 443, | |
} | |
); | |
listener.addTargetGroups( | |
fargateService.loadBalancer.loadBalancerArn, | |
{ | |
targetGroups: [fargateService.targetGroup], | |
}); | |
listener.addCertificateArns( | |
fargateService.loadBalancer.loadBalancerArn, | |
[certificate.certificateArn], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment