AWS CloudFormation의 동일한 상위 스택 내에 있는 중첩된 스택 간에 값을 전달하려면 어떻게 해야 합니까?

2분 분량
0

AWS CloudFormation의 동일한 상위 스택 내에 있는 중첩된 2개의 스택 간에 값을 전달하거나 공유하려고 합니다.

간략한 설명

해결 방법에서는 다음과 같이 가정합니다.

  • 동일한 상위 스택에 NestedStackANestedStackB라는 2개의 중첩된 스택이 있습니다.
  • NestedStackB에서 NestedStackA의 값을 사용하려고 합니다.

해결 방법

  1. FSP AWS CloudFormation 템플릿에서 소스 스택(NestedStackA)의 출력으로 공유하려는 값을 전달합니다. 다음의 JSON 및 YAML 예제를 참조하십시오.

JSON:

"Outputs": {
    "SharedValueOutput": {
        "Value": "yourValue",
        "Description": "You can refer to any resource from the template."
    }
}

YAML:

Outputs:
  SharedValueOutput:
    Value: yourValue         
    Description: You can refer to any resource from the template.
  1. FSP 대상 스택(NestedStackB)에서 파라미터를 생성합니다. 다음의 JSON 및 YAML 예제를 참조하십시오.

JSON:

"Parameters": {
    "SharedValueParameter": {
        "Type": "String",
        "Description": "The shared value will be passed to this parameter by the parent stack."
    }
}

YAML:

Parameters: 
  SharedValueParameter: 
    Type: String
    Description: The shared value will be passed to this parameter by parent stack.
  1. FSP NestedStackA의 출력 값을 NestedStackB에 대한 파라미터 값으로 전달합니다. 상위 스택에서 이 값에 액세스하려면 Fn::GetAtt 함수를 사용하십시오. 논리적 이름 NestedStackAOutputs.NestedStackOutputName 형식의 출력 값 이름을 사용합니다. 다음의 JSON 및 YAML 예제를 참조하십시오.

JSON:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "NestedStackA": {
      "Type": "AWS::CloudFormation::Stack",
      "Properties": {
        "TemplateURL": "<S3 URL for the template>"
      }
    },
    "NestedStackB": {
      "Type": "AWS::CloudFormation::Stack",
      "Properties": {
        "TemplateURL": "<S3 URL for the template>",
        "Parameters": {
          "SharedValueParameter": {
            "Fn::GetAtt": [
              "NestedStackA",
              "Outputs.SharedValueOutput"
            ]
          }
        }
      }
    }
  }
}

YAML:

AWSTemplateFormatVersion: 2010-09-09
Resources:
  NestedStackA:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      TemplateURL: <S3 URL for the template>
  NestedStackB:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      TemplateURL: <S3 URL for the template>
      Parameters:
        SharedValueParameter: 
          Fn::GetAtt: 
          - NestedStackA
          - Outputs.SharedValueOutput

관련 정보

중첩 스택 작업

AWS:: CloudFormation:: Stack

AWS CloudFormation 템플릿 코드 조각

AWS 공식
AWS 공식업데이트됨 2년 전
댓글 없음

관련 콘텐츠