Cloudformation Creation of Instances using Count Macro

0

If I am creating WebServer instances using Cloudformation with the Count Macro, how do you get different names and tags per instance created?

질문됨 일 년 전256회 조회
1개 답변
0

The documentation for the Count Macro in github is pretty clear. You can include a %d anywhere in a tag-value and Count will replace it with the iteration #.

Given:

AWSTemplateFormatVersion: "2010-09-09"
Transform: Count
Resources:
  Bucket:
    Type: AWS::S3::Bucket
    Properties:
      Tags:
        - Key: TestKey
          Value: my bucket %d
    Count: 3

This will create three S3 buckets with the first bucket having tag TestKey = "my bucket 1", the 2nd bucket having tag TestKey = "my bucket 2" etc.

Since resource names are defined as a tag with the key = 'Name', you can apply the '%d' in the Name tag-value to. In fact, if you're going to set the 'Name' tag for a resource type using Count you must use the '%d' otherwise Count will apply the same 'Name' tag-value to each iteration and CFT will fail trying to create the 2nd instance because the first instance already has the name.

AWS
Scott_K
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠