Amazon cloudformation 在CloudFormation/Serverless中创建AWS::S3::记录集时如何引用CloudFront域名?
我有一个项目,它有一个cloudfront发行版,可以从一个存储桶中提供一些数据。我使用的是无服务器框架,但我认为这主要是一个云形成问题 我想在Route53托管的域中创建A记录(如果有必要的话,第三级域,即:dashboard.domain.com指向Route53,我正在尝试添加.dashboard.domain.com) 我就是不知道如何引用CloudFront资源的输出 这就是我现在所拥有的,它之所以有效是因为它是静态的。但是,我需要自动将另一个资源创建的云前端域放入正确的云前端域。我想这是我能做的某种类型的GetAttr,但我就是不能让它工作Amazon cloudformation 在CloudFormation/Serverless中创建AWS::S3::记录集时如何引用CloudFront域名?,amazon-cloudformation,amazon-cloudfront,serverless,Amazon Cloudformation,Amazon Cloudfront,Serverless,我有一个项目,它有一个cloudfront发行版,可以从一个存储桶中提供一些数据。我使用的是无服务器框架,但我认为这主要是一个云形成问题 我想在Route53托管的域中创建A记录(如果有必要的话,第三级域,即:dashboard.domain.com指向Route53,我正在尝试添加.dashboard.domain.com) 我就是不知道如何引用CloudFront资源的输出 这就是我现在所拥有的,它之所以有效是因为它是静态的。但是,我需要自动将另一个资源创建的云前端域放入正确的云前端域。我想
DNSRecords:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneId: Z09193931V4YGJEPVMLG1
RecordSets:
- Name: prod.dashboard.domain.com
Type: A
AliasTarget:
HostedZoneId: Z2FDTNDATAQYW2
DNSName: someid.cloudfront.net
编辑:已更新以包含WebAppCloudFrontDistribution您尚未提供您的
AWS::CloudFront::Distribution
资源定义,因此我只能基于一个示例
MyCloudFrontDistro:
Type: AWS::CloudFront::Distribution
Properties:
# some properties
然后您可以修改您的DNSRecords
DNSRecords:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneId: Z09193931V4YGJEPVMLG1
RecordSets:
- Name: prod.dashboard.domain.com
Type: A
AliasTarget:
HostedZoneId: !Ref MyCloudFrontDistro
DNSName: !GetAtt MyCloudFrontDistro.DomainName
以下是我的有效解决方案,请注意以下几点
- Z2FDTNDAQYW2的HostedZoneId是cloudfront域专用的。在引用云前端资源时需要使用它
- HostedZoneName上需要包含尾随空格(如果与HostedZoneId相比使用尾随空格)。在我的例子中,我在云形成之前就有了域设置
DNSRecords:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneId: Z09193931V4YGJEPVMLG1
RecordSets:
- Name: prod.dashboard.domain.com
Type: A
AliasTarget:
HostedZoneId: !Ref MyCloudFrontDistro
DNSName: !GetAtt MyCloudFrontDistro.DomainName
WebAppCloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName:
Fn::Join: [
"", [
{ "Ref": "WebAppS3Bucket" },
".s3.amazonaws.com"
]
]
## An identifier for the origin which must be unique within the distribution
Id: WebApp
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: https-only
Enabled: 'true'
Aliases:
- ${self:provider.stage}.dashboard.domain.com
DefaultRootObject: index.html
CustomErrorResponses:
- ErrorCode: 404
ResponseCode: 200
ResponsePagePath: /index.html
DefaultCacheBehavior:
AllowedMethods:
- DELETE
- GET
- HEAD
- OPTIONS
- PATCH
- POST
- PUT
TargetOriginId: WebApp
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
## The protocol that users can use to access the files in the origin. To allow HTTP use `allow-all`
ViewerProtocolPolicy: redirect-to-https
## The certificate to use when viewers use HTTPS to request objects.
ViewerCertificate:
AcmCertificateArn:
Ref: SSLCertificate
SslSupportMethod: sni-only
MinimumProtocolVersion: TLSv1
## Uncomment the following section in case you want to enable logging for CloudFront requests
# Logging:
# IncludeCookies: 'false'
# Bucket: mylogs.s3.amazonaws.com
# Prefix: myprefix
Resources:
DNSRecords:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneName: dashboard.domain.com.
RecordSets:
- Name: ${self:provider.stage}.dashboard.domain.com
Type: A
AliasTarget:
HostedZoneId: Z2FDTNDATAQYW2
DNSName: !GetAtt WebAppCloudFrontDistribution.DomainName