AWS CloudFormation 템플릿의 개별 파라미터에 여러 값을 사용하려면 어떻게 해야 합니까?
최종 업데이트 날짜: 2020년 8월 20일
개별 파라미터에 여러 값을 사용하여 AWS CloudFormation 템플릿에서 스택을 생성 또는 업데이트하고 싶습니다.
간략한 설명
다음과 같은 방법으로 AWS CloudFormation 템플릿에서 개별 파라미터에 여러 값을 전달할 수 있습니다.
- AWS 관련 파라미터 유형을 사용하여 AWS 계정에서 미리 채워진 기존 AWS 값 목록에서 값을 선택합니다.
- CommaDelimitedList 파라미터 유형을 사용하여 고유한 값을 지정합니다.
해결 방법
AWS 관련 파라미터 유형을 사용하여 AWS 계정에서 미리 채워진 기존 AWS 값 목록에서 값을 선택합니다.
중요: AWS CloudFormation은 계정의 기존 값에 대해 선택한 입력 값을 검증합니다.
다음 샘플 AWS CloudFormation 템플릿에서 SecurityGroups 키가 있는 파라미터는 SecurityGroupIds에 여러 값을 허용할 수 있는 AWS 관련 파라미터 유형을 지정합니다.
JSON 템플릿:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"SecurityGroups": {
"Type": "List<AWS::EC2::SecurityGroup::Id>",
"Description": "The list of SecurityGroupIds in your Virtual Private Cloud (VPC)"
}
},
"Resources": {
"MyEC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-79fd7eee",
"KeyName": "testkey",
"SecurityGroupIds": {
"Ref": "SecurityGroups"
}
}
}
}
}
YAML 템플릿:
AWSTemplateFormatVersion: 2010-09-09
Parameters:
SecurityGroups:
Type: 'List<AWS::EC2::SecurityGroup::Id>'
Description: The list of SecurityGroupIds in your Virtual Private Cloud (VPC)
Resources:
MyEC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: ami-79fd7eee
KeyName: testkey
SecurityGroupIds: !Ref SecurityGroups
CommaDelimitedList 파라미터 유형을 사용하여 입력 값 입력
다음 샘플 AWS CloudFormation 템플릿에서 SecurityGroups 키가 있는 파라미터는 SecurityGroupIds에 여러 값을 허용할 수 있는 CommaDelimitedList 유형을 지정합니다.
JSON 템플릿:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"SecurityGroups": {
"Type": "CommaDelimitedList",
"Description": "The list of SecurityGroupIds in your Virtual Private Cloud (VPC)",
"Default": "sg-a123fd85, sg-b456ge94"
}
},
"Resources": {
"MyEC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-79fd7eee",
"KeyName": "testkey",
"SecurityGroupIds": {
"Ref": "SecurityGroups"
}
}
}
}
}
YAML 템플릿:
AWSTemplateFormatVersion: 2010-09-09
Parameters:
SecurityGroups:
Type: CommaDelimitedList
Description: The list of SecurityGroupIds in your Virtual Private Cloud (VPC)
Default: sg-a123fd85, sg-b456ge94
Resources:
MyEC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: ami-79fd7eee
KeyName: testkey
SecurityGroupIds: !Ref SecurityGroups