AWS CloudFormation の同じ親スタック内にあるネストされたスタック間で値を渡す方法を教えてください。

所要時間2分
0

AWS CloudFormation の同じ親スタック内にある 2 つのネストされたスタック間で、値を渡したり共有したりすることを考えています。

簡単な説明

この解決方法では、以下を前提としています。

  • 同じ親スタックの一部である NestedStackANestedStackB がある。
  • NestedStackA の値を NestedStackB で使用する。

解決方法

  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] 関数を使用します。NestedStackA の論理名と Outputs.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年前
コメントはありません

関連するコンテンツ