Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Multiple S3 Buckets having same properties with cloudformation

I'm trying to create multiple S3 bucktes with same propeties.But I'm not able to create multiple s3 buckets.

I found in http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html if you have multiple resources of the same type, you can declare them together by separating them with commas

But I didn't find any example and I'm not sure how to do it.I tried debugging but not getting the result. Please suggest. Below is my yaml file:

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
like image 328
SmrutiRanjan Avatar asked May 14 '26 16:05

SmrutiRanjan


1 Answers

In a CloudFormation template, each resource must be declared separately. So, even if your buckets have identical properties, they still must be individually declared:

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

However,

You must declare each resource separately; however, if you have multiple resources of the same type, you can declare them together by separating them with commas.

The wording of this text does imply there is a shortcut to avoid duplication, but I have never seen such a working example.

like image 64
Matt Houser Avatar answered May 16 '26 06:05

Matt Houser