Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 在云形成产生云锋后,最好的方法是什么?_Amazon Web Services_Amazon Cloudformation - Fatal编程技术网

Amazon web services 在云形成产生云锋后,最好的方法是什么?

Amazon web services 在云形成产生云锋后,最好的方法是什么?,amazon-web-services,amazon-cloudformation,Amazon Web Services,Amazon Cloudformation,我正在创建一个完全无服务器的解决方案,它将创建一个s3 bucket和CloudFront。使用bitbucket管道中的云形成模板 我还想为CloudFront创建invalidate 1) 是否有可能在云形成过程中造成失效 2) 如果没有,那么我如何从我的云结构中获取分发id,然后使用aws cli创建无效声明 CFDistribution: Type: 'AWS::CloudFront::Distribution' DependsOn: UIBucket Properties: Dis

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

我还想为CloudFront创建invalidate

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允许3种与CloudFront相关的类型

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(选中此项):

最后,创建:


谢谢,我还找到了另一种方法,那就是在template.yaml中,我使用了list exports`CFDistributionID:Value:!Ref CFDistribution Description:Cloudfront分发ID导出:名称:!Sub${AWS::StackName}:CFDistributionID`并使用CLI
AWS cloudformation列表导出--查询“导出[?名称!=null]|[?包含(名称,'xyz-UI:CFDistributionID')]”。值|[0]
,它将返回我“分发id”,然后我可以使用您的最后一个命令
$ distributionId=${aws cloudformation describe-stacks --stack-name MY_STACK --query "Stacks[0].Outputs[?OutputKey=='CloudFrontDistributionID'].OutputValue" --output text}
$ aws cloudfront create-invalidation --distribution-id $distributionId --paths /index.html /error.html