我想使用 AWS CloudFormation 将多个 AWS Certificate Manager (ACM) SSL 和 TLS 证书与应用程序负载均衡器进行关联。
解决方法
要为安全侦听器添加默认 SSL 或 TLS 服务器,请对 AWS::ElasticLoadBalancingV2::Listener 资源使用 Certificates 属性。此资源提供了一个证书。要添加更多证书,请使用 AWS::ElasticLoadBalancingV2::ListenerCertificate。AWS::ElasticLoadBalancingV2::ListenerCertificate 包含接受证书列表的 Certificates 参数。
要使用一个默认证书创建应用程序负载均衡器侦听器,请使用以下 CloudFormation 模板:
HTTPlistener:
Type: 'AWS::ElasticLoadBalancingV2::Listener'
DependsOn: ApplicationLoadBalancer
Properties:
DefaultActions:
- Type: fixed-response
FixedResponseConfig:
ContentType: text/plain
MessageBody: Success
StatusCode: '200'
LoadBalancerArn: >-
arn:aws:elasticloadbalancing:Region:AccountID:loadbalancer/app/TestACMELB/1032d48308c9b37f
Port: '443'
Protocol: HTTPS
Certificates:
- CertificateArn: >-
arn:aws:acm:Region:AccountID:certificate/cffb8a69-0817-4e04-bfb1-dac7426d6b90
要向应用程序负载均衡器侦听器添加多个证书,请使用以下 CloudFormation 模板:
AdditionalCertificates:
Type: 'AWS::ElasticLoadBalancingV2::ListenerCertificate'
DependsOn: HTTPlistener
Properties:
Certificates:
- CertificateArn: >-
arn:aws:acm:Region:AccountID:certificate/c71a3c29-e79d-40e6-8834-650fe0d54a3f
- CertificateArn: >-
arn:aws:acm:Region:AccountID:certificate/fff1c1ba-3d97-4735-b3d5-9c5269b75db3
ListenerArn:
Ref: HTTPlistener
**注意:**在前面的模板中,将 Region 替换为您的 AWS 区域,将 AccountID 替换为您的 AWS 账户。此外,将 LoadBalancerARN 和 CertificateARN 的值替换为应用程序负载均衡器和证书 ARN。