简体   繁体   English

有没有办法在 AWS cloudformation 中配置嵌套堆栈的“堆栈名称”?

[英]Is there a way to configure the 'Stack Name' of nested stacks in AWS cloudformation ?

I am trying to create a nested stack using AWS CloudFormation.我正在尝试使用 AWS CloudFormation 创建嵌套堆栈。 I need to specify the 'Stack Name' of the nested stack.我需要指定嵌套堆栈的“堆栈名称”。 I tried using the 'Tags' property with Key: 'Stack Name'.我尝试将 'Tags' 属性与 Key: 'Stack Name' 一起使用。 But that didn't help.但这没有帮助。 Is there any way to provide the Stack Name as an input while creating nested stack?有没有办法在创建嵌套堆栈时提供堆栈名称作为输入?

In a given template, you have access to the pseudo-parameters stackId and stackName.在给定的模板中,您可以访问伪参数 stackId 和 stackName。 Those can be marked for export, then referenced in another stack.这些可以标记为导出,然后在另一个堆栈中引用。 Joined, they give you the child stack's name.加入后,他们会为您提供子堆栈的名称。

I found the following video quite useful despite its age: https://youtu.be/6R44BADNJA8尽管年代久远,我发现以下视频非常有用: https : //youtu.be/6R44BADNJA8

This sample template may also be helpful in understanding how these work: https://s3.amazonaws.com/cloudformation-examples/user-guide/cross-stack/SampleNetworkCrossStack.template此示例模板也可能有助于理解这些工作原理: https : //s3.amazonaws.com/cloudformation-examples/user-guide/cross-stack/SampleNetworkCrossStack.template

{ "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "AWS CloudFormation Sample Template VPC_with_PublicIPs_And_DNS: Sample template that creates a VPC with DNS and public IPs enabled. Note that you are billed for the AWS resources that you use when you create a stack from this template.", "Resources" : { "VPC" : { "Type" : "AWS::EC2::VPC", "Properties" : { "EnableDnsSupport" : "true", "EnableDnsHostnames" : "true", "CidrBlock" : "10.0.0.0/16" } }, "PublicSubnet" : { "Type" : "AWS::EC2::Subnet", "Properties" : { "VpcId" : { "Ref" : "VPC" }, "CidrBlock" : "10.0.0.0/24" } }, "InternetGateway" : { "Type" : "AWS::EC2::InternetGateway" }, "VPCGatewayAttachment" : { "Type" : "AWS::EC2::VPCGatewayAttachment", "Properties" : { "VpcId" : { "Ref" : "VPC" }, "InternetGatewayId" : { "Ref" : "InternetGateway" } } }, "PublicRouteTable" : { "Type" : "AWS::EC2::RouteTable", "Properties" : { "VpcId" : { "Ref" : "VPC" } } }, "PublicRoute" : { "Type" : "AWS::EC2::Route", "DependsOn" : "VPCGatewayAttachment", "Properties" : { "RouteTableId" : { "Ref" : "PublicRouteTable" }, "DestinationCidrBlock" : "0.0.0.0/0", "GatewayId" : { "Ref" : "InternetGateway" } } }, "PublicSubnetRouteTableAssociation" : { "Type" : "AWS::EC2::SubnetRouteTableAssociation", "Properties" : { "SubnetId" : { "Ref" : "PublicSubnet" }, "RouteTableId" : { "Ref" : "PublicRouteTable" } } }, "PublicSubnetNetworkAclAssociation" : { "Type" : "AWS::EC2::SubnetNetworkAclAssociation", "Properties" : { "SubnetId" : { "Ref" : "PublicSubnet" }, "NetworkAclId" : { "Fn::GetAtt" : ["VPC", "DefaultNetworkAcl"] } } }, "WebServerSecurityGroup" : { "Type" : "AWS::EC2::SecurityGroup", "Properties" : { "GroupDescription" : "Enable HTTP ingress", "VpcId" : { "Ref" : "VPC" }, "SecurityGroupIngress" : [ { "IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0" } ] } } }, "Outputs" : { "VPCId" : { "Description" : "VPC ID", "Value" : { "Ref" : "VPC" }, "Export" : { "Name" : {"Fn::Sub": "${AWS::StackName}-VPCID" }} }, "PublicSubnet" : { "Description" : "The subnet ID to use for public web servers", "Value" : { "Ref" : "PublicSubnet" }, "Export" : { "Name" : {"Fn::Sub": "${AWS::StackName}-SubnetID" }} }, "WebServerSecurityGroup" : { "Description" : "The security group ID to use for public web servers", "Value" : { "Fn::GetAtt" : ["WebServerSecurityGroup", "GroupId"] }, "Export" : { "Name" : {"Fn::Sub": "${AWS::StackName}-SecurityGroupID" }} } } }

As commented below, the answer is no for now.正如下面所评论的,现在答案是否定的。

Original:Yes, it's the resource name that gets taken as the stack name.原文:是的,它是作为堆栈名称的资源名称。 Below you'd get a stack called myStackName下面你会得到一个名为 myStackName 的堆栈

YAML YAML

AWSTemplateFormatVersion: "2010-09-09"
Resources: 
  myStackName: 
Type: "AWS::CloudFormation::Stack"
Properties: 
  TemplateURL: "https://s3.amazonaws.com/cloudformation-templates-us-east-1/EC2ChooseAMI.template"
  Parameters: 
    InstanceType: "t1.micro"
    KeyName: "mykey"

JSON JSON

{
"AWSTemplateFormatVersion" : "2010-09-09",
   "Resources" : {
  "myStackName" : {
     "Type" : "AWS::CloudFormation::Stack",
     "Properties" : {
        "TemplateURL" : "https://s3.amazonaws.com/cloudformation-templates-us-east-1/EC2ChooseAMI.template",
        "Parameters" : {
           "InstanceType" : "t1.micro",
           "KeyName" : "mykey"
        }
     }
  }
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM