【问题标题】:Create Multiple S3 Buckets having same properties with cloudformation使用 cloudformation 创建具有相同属性的多个 S3 存储桶
【发布时间】:2017-08-30 21:45:08
【问题描述】:

我正在尝试创建多个具有相同属性的 S3 存储桶。但我无法创建多个 s3 存储桶。

我发现在http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html 如果你有多个相同类型的资源,你可以用逗号分隔它们一起声明

但我没有找到任何示例,也不知道该怎么做。我尝试调试但没有得到结果。 请建议。 以下是我的 yaml 文件:

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  myS3Bucketlo:
    Type: AWS::S3::Bucket
    Properties:
      AccessControl: AuthenticatedRead
Outputs:
  WebsiteURL:
    Value: !GetAtt myS3Bucketlo.WebsiteURL
    Description: URL for the website hosted on S3

【问题讨论】:

    标签: amazon-web-services amazon-s3 cloud amazon-cloudformation


    【解决方案1】:

    在 CloudFormation 模板中,每个资源都必须单独声明。因此,即使您的存储桶具有相同的属性,它们仍然必须单独声明:

    AWSTemplateFormatVersion: '2010-09-09'
    Resources:
      bucket1:
        Type: AWS::S3::Bucket
        Properties:
          AccessControl: AuthenticatedRead
      bucket2:
        Type: AWS::S3::Bucket
        Properties:
          AccessControl: AuthenticatedRead
      bucket3:
        Type: AWS::S3::Bucket
        Properties:
          AccessControl: AuthenticatedRead
    Outputs:
      WebsiteURL1:
        Value: !GetAtt bucket1.WebsiteURL
        Description: URL for the website 1 hosted on S3
      WebsiteURL2:
        Value: !GetAtt bucket2.WebsiteURL
        Description: URL for the website 2 hosted on S3
      WebsiteURL3:
        Value: !GetAtt bucket3.WebsiteURL
        Description: URL for the website 3 hosted on S3
    

    然而,

    您必须单独声明每个资源;但是,如果你有多个相同类型的资源,你可以用逗号分隔它们一起声明。

    本文的措辞确实暗示了避免重复的捷径,但我从未见过这样的工作示例。

    【讨论】:

    • 我也没有得到任何这样的例子,我最终使用了 teraform,我发现使用 count 声明多个相同类型的资源很容易。
    • 这个例子也帮助了我。每个存储桶必须有不同的名称,否则只会创建一个存储桶。
    猜你喜欢
    • 2020-02-08
    • 2021-08-14
    • 1970-01-01
    • 2016-08-23
    • 2016-12-09
    • 1970-01-01
    • 2023-03-18
    • 2020-09-07
    • 2021-09-17
    相关资源
    最近更新 更多