Come faccio a passare valori tra stack annidati all'interno dello stesso stack principale in AWS CloudFormation?

2 minuti di lettura
0

Desidero passare o condividere un valore tra due stack annidati all'interno dello stesso stack principale in AWS CloudFormation.

Breve descrizione

La risoluzione presuppone quanto segue:

  • Hai due stack annidati, NestedStackA e NestedStackB, che fanno parte dello stesso stack principale.
  • Si desidera utilizzare un valore di NestedStackA in NestedStackB.

Risoluzione

1.FCrea il tuo modello AWS CloudFormation, passa il valore che desideri condividere come output nel tuo stack di origine (NestedStackA). Guarda i seguenti esempi JSON e 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.

2.fspCrea un parametro nello stack di destinazione ( NestedStackB). Guarda i seguenti esempi JSON e 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.

3.fspPassa il valore di output da NestedStackA come valore del parametro per NestedStackB. Per accedere a questo valore nello stack principale, usa la funzione Fn::GetAtt. Utilizzate il nome logico di NestedStackA e il nome del valore di output nel formato Outputs.NestedStackOutputName. Guarda i seguenti esempi JSON e 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

Informazioni correlate

Utilizzo di pile annidate

AWS::CloudFormation::Stack

Frammenti di modello AWS CloudFormation

AWS UFFICIALE
AWS UFFICIALEAggiornata 2 anni fa