¿Cómo puedo transferir valores entre pilas anidadas en la misma pila principal en AWS CloudFormation?

2 minutos de lectura
0

Deseo transferir o compartir un valor entre dos pilas anidadas en la misma pila principal en AWS CloudFormation.

Descripción breve

La solución asume lo siguiente:

  • Tiene dos pilas anidadas, NestedStackA y NestedStackB, que forman parte de la misma pila principal.
  • Desea usar un valor de NestedStackA en NestedStackB.

Resolución

  1. FSPEn su plantilla de AWS CloudFormation, transfiera el valor que desea compartir como una salida en su pila de origen (NestedStackA). Consulte los siguientes ejemplos de JSON y 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. FSPCree un parámetro en la pila de destino (NestedStackB). Consulte los siguientes ejemplos de JSON y 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. FSPTransfiera el valor de salida de NestedStackA como valor de parámetro para NestedStackB. Para acceder a este valor en la pila principal, utilice la función Fn::GetAtt. Utilice el nombre lógico de NestedStackA y el nombre del valor de salida en formato Outputs.NestedStackOutputName. Consulte los siguientes ejemplos de JSON y 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

Información relacionada

Trabajar con pilas anidadas

AWS::CloudFormation::Stack

Fragmentos de plantillas de AWS CloudFormation

OFICIAL DE AWS
OFICIAL DE AWSActualizada hace 2 años