gpt4 book ai didi

amazon-web-services - cloudformation 创建 cloudfront 后创建失效的最佳方法是什么?

转载 作者:行者123 更新时间:2023-12-03 15:10:50 25 4
gpt4 key购买 nike

我正在创建一个完全无服务器的解决方案,它将创建一个 s3 存储桶和 CloudFront。使用来自 bitbucket 管道的云形成模板

我还想为 CloudFront 创建无效。

1) 是否有可能在云形成过程中造成失效?

2) 如果不是,那么如何从我的云结构中获取分发 ID,然后使用 aws cli 创建失效

CFDistribution:
Type: 'AWS::CloudFront::Distribution'
DependsOn: UIBucket
Properties:
DistributionConfig:
Aliases:
- !Sub "${AppSubDomain}.${SSMDomain}"
Origins:
- DomainName: !GetAtt UIBucket.DomainName
Id: S3BucketOrigin
S3OriginConfig:
OriginAccessIdentity: !Join
- ''
- - 'origin-access-identity/cloudfront/'
- !Ref CFOriginAccessIdentity
Comment: !Sub 'CloudFront origin for ${AppSubDomain}.${SSMDomain}'
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: S3BucketOrigin
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
ViewerProtocolPolicy: redirect-to-https
DefaultRootObject: index.html
Enabled: 'true'
HttpVersion: http2
PriceClass: PriceClass_All
ViewerCertificate:
AcmCertificateArn: !Ref SSMWildcardCertificateARN
SslSupportMethod: sni-only
Tags:
- Key: "Type"
Value: "Host"
- Key: "Product"
Value: !Ref Product
- Key: "Environment"
Value: !Ref SSMEnvironment

最佳答案

我也将 CloudFront 与 CloudFormation 结合使用,但没有找到使用 CloudFormation 创建失效的方法。如果您检查AWS文档,CloudFormation允许与CloudFront相关的3种类型

CloudFront
AWS::CloudFront::CloudFrontOriginAccessIdentity
AWS::CloudFront::Distribution
AWS::CloudFront::StreamingDistribution

并且这些都不会造成失效。回答你的第一个问题:

1) 是否有可能在云形成过程中造成失效?

没有。

2) 如果不是,那么如何从我的云结构中获取分发 ID,然后使用 aws cli 创建失效

您可以将分发添加到 CloudFormation 模板输出:

Outputs:
CloudFrontDistributionID:
Description: 'CloudFront distribution ID'
Value: !Ref CloudFrontDistribution
CloudFrontURL:
Description: 'CloudFront URL'
Value:!GetAtt CloudFrontDistribution.DomainName

使用 bash 保存发行版 ID(检查此 question ):

$ distributionId=${aws cloudformation describe-stacks --stack-name MY_STACK --query "Stacks[0].Outputs[?OutputKey=='CloudFrontDistributionID'].OutputValue" --output text}

最后,创建 CloudFront invalidation :

$ aws cloudfront create-invalidation --distribution-id $distributionId --paths /index.html /error.html

关于amazon-web-services - cloudformation 创建 cloudfront 后创建失效的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57033968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com