【发布时间】:2020-10-16 08:52:57
【问题描述】:
我正在 ECS 上设置 grafana,并希望它可以通过不同子域上的两个不同 URL 访问:grafana.subdomain.mycompany.com 和 grafana.mycompany.com(我们需要两个 URL,因为子域版本需要grafana auth 代理,而非子域版本用于编辑仪表板)。
我的问题是 ApplicationLoadBalancedFargateService 只允许您提供一个证书。
到目前为止,我最好的解决方案是这样做。
const grafanaService = new ecs_patterns.ApplicationLoadBalancedFargateService(this, 'Grafana', {
cluster: this.props.ecsCluster,
taskDefinition: taskdef,
domainZone: this.props.hostedZone,
domainName: this.grafanaDns,
publicLoadBalancer: true
})
const sslListener = grafanaService.loadBalancer.addListener('SSL', {
port: 443,
certificates: [this.props.certificateHarvestSubdomain, this.props.certificateRootSubdomain],
protocol: ApplicationProtocol.HTTPS
})
sslListener.addTargets('grafanaTarget', {
targets: [grafanaService.service],
port: 80,
protocol: ApplicationProtocol.HTTP,
healthCheck: {
path: '/login',
interval: cdk.Duration.minutes(1)
}
})
new ARecord(this, 'Alias', {
zone: this.props.hostedZone,
target: route53.RecordTarget.fromAlias(new LoadBalancerTarget(grafanaService.loadBalancer)),
recordName: 'grafana'
})
这可以解决问题,但它给我留下了一个问题:我无法进行 HTTP 到 HTTPS 的重定向,因为 ApplicationLoadBalancedFargateService 已经在端口 80 上创建了一个侦听器,而我找不到访问现有侦听器的方法。如果我尝试创建另一个侦听器,则无法说明侦听器已存在。
【问题讨论】:
标签: aws-cdk