가상 파라미터를 사용하여 AWS 값 가져오기 - AWS CloudFormation

가상 파라미터를 사용하여 AWS 값 가져오기

가상 파라미터는 CloudFormation에서 사전 정의되며 템플릿에서 선언할 필요가 없습니다. 템플릿의 하드 코딩 값 대신 Ref 또는 Sub 내장 함수와 함께 사용하여 AWS 계정, 리전 및 기타 컨텍스트 데이터에 대한 컨텍스트 정보에 액세스할 수 있습니다.

구문

Ref 내장 함수와 함께 가상 파라미터를 사용하려면 기본 구문은 다음과 같습니다.

JSON

{ "Ref" : "AWS::PseudoParameter" }

YAML

!Ref AWS::PseudoParameter

Sub 내장 함수와 함께 가상 파라미터를 사용하려면 기본 구문은 다음과 같습니다.

JSON

{ "Fn::Sub" : "${AWS::PseudoParameter}" }

YAML

!Sub '${AWS::PseudoParameter}'

예제

다음 코드 조각에서는 AWS::Region 가상 파라미터의 값을 출력 값에 할당합니다.

JSON

"Outputs" : { "MyStacksRegion" : { "Value" : { "Ref" : "AWS::Region" } } }

YAML

Outputs: MyStacksRegion: Value: !Ref "AWS::Region"

사용 가능한 의사 파라미터

AWS::AccountId

스택이 생성되는 계정의 AWS 계정 ID를 반환합니다(예: 123456789012).

AWS::NotificationARNs

현재 스택에 대한 알림 Amazon 리소스 이름(ARN) 목록을 반환합니다.

목록에서 단일 ARN을 가져오려면 Fn::Select를 사용합니다. 자세한 내용은 Fn::Select 섹션을 참조하세요.

JSON

"myASGrpOne" : { "Type" : "AWS::AutoScaling::AutoScalingGroup", "Version" : "2009-05-15", "Properties" : { "AvailabilityZones" : [ "us-east-1a" ], "LaunchConfigurationName" : { "Ref" : "MyLaunchConfiguration" }, "MinSize" : "0", "MaxSize" : "0", "NotificationConfigurations" : [{ "TopicARN" : { "Fn::Select" : [ "0", { "Ref" : "AWS::NotificationARNs" } ] }, "NotificationTypes" : [ "autoscaling:EC2_INSTANCE_LAUNCH", "autoscaling:EC2_INSTANCE_LAUNCH_ERROR" ] }] } }

YAML

myASGrpOne: Type: AWS::AutoScaling::AutoScalingGroup Version: '2009-05-15' Properties: AvailabilityZones: - "us-east-1a" LaunchConfigurationName: Ref: MyLaunchConfiguration MinSize: '0' MaxSize: '0' NotificationConfigurations: - TopicARN: Fn::Select: - '0' - Ref: AWS::NotificationARNs NotificationTypes: - autoscaling:EC2_INSTANCE_LAUNCH - autoscaling:EC2_INSTANCE_LAUNCH_ERROR

AWS::NoValue

Fn::If 내장 함수에 반환 값으로 지정된 경우 해당 리소스 속성을 제거합니다.

예를 들어, 스냅샷 ID가 제공된 경우에만 Amazon RDS DB 인스턴스에 대한 스냅샷을 사용하려는 경우 AWS::NoValue 파라미터를 사용할 수 있습니다. UseDBSnapshot 조건이 true로 평가되면 CloudFormation에서는 DBSnapshotIdentifier 속성에 대한 DBSnapshotName 파라미터 값을 사용합니다. 조건이 false로 평가되면 CloudFormation이 DBSnapshotIdentifier 속성을 제거합니다.

JSON

"MyDB" : { "Type" : "AWS::RDS::DBInstance", "Properties" : { "AllocatedStorage" : "5", "DBInstanceClass" : "db.t2.small", "Engine" : "MySQL", "EngineVersion" : "5.5", "MasterUsername" : { "Ref" : "DBUser" }, "MasterUserPassword" : { "Ref" : "DBPassword" }, "DBParameterGroupName" : { "Ref" : "MyRDSParamGroup" }, "DBSnapshotIdentifier" : { "Fn::If" : [ "UseDBSnapshot", {"Ref" : "DBSnapshotName"}, {"Ref" : "AWS::NoValue"} ] } } }

YAML

MyDB: Type: AWS::RDS::DBInstance Properties: AllocatedStorage: '5' DBInstanceClass: db.t2.small Engine: MySQL EngineVersion: '5.5' MasterUsername: Ref: DBUser MasterUserPassword: Ref: DBPassword DBParameterGroupName: Ref: MyRDSParamGroup DBSnapshotIdentifier: Fn::If: - UseDBSnapshot - Ref: DBSnapshotName - Ref: AWS::NoValue

AWS::Partition

리소스가 있는 파티션을 반환합니다. 표준 AWS 리전에서 파티션은 aws입니다. 다른 파티션에 있는 리소스의 경우 파티션은 aws-partitionname입니다. 예를 들어 중국(베이징 및 닝샤) 리전에 있는 리소스에 대한 파티션은 aws-cn이고, AWS GovCloud(미국 서부) 리전에 있는 리소스에 대한 파티션은 aws-us-gov입니다.

AWS::Region

포괄 리소스를 생성하는 리전을 나타내는 문자열을 반환합니다(예: us-west-2).

AWS::StackId

create-stack 명령으로 지정된 스택의 ID를 반환합니다(예: arn:aws:cloudformation:us-west-2:123456789012:stack/teststack/51af3dc0-da77-11e4-872e-1234567db123).

AWS::StackName

create-stack 명령으로 지정된 스택의 이름을 반환합니다(예: teststack).

AWS::URLSuffix

도메인에 대한 접미사를 반환합니다. 접미사는 일반적으로 amazonaws.com이지만 리전에 따라 다를 수 있습니다. 예를 들어 중국(베이징) 리전의 접미사는 amazonaws.com.cn입니다.