AWS CloudFormation:嵌套堆栈 - 未解决的依赖项

时间:2017-04-14 01:16:11

标签: amazon-web-services parameters nested dependencies amazon-cloudformation

好吧,所以我从主模板调用嵌套堆栈。我以为我已经想出如何正确导出值并在嵌套堆栈之间导入。我意识到很多我的命名约定格式都没有达到标准,我本周才开始学习CloudFormation Scripting。

每当我尝试创建这个堆栈时,它们都会创建,直到我进入“公共路线”,此时我得到一个:

Template format error: Unresolved resource dependencies [InternetGatewayStackname] in the Resources block of the template

据我所知,我做的公共路由与Vpc堆栈完全相同,这有效。出于某种原因,我无法让公共路线发挥作用。

主要筹码:

{
    "AWSTemplateFormatVersion" : "2010-09-09",
    "Description" : "Master template, creates three private subnets, one public, two routes, an internetgateway, nat gateway, and bastion host.",
    "Parameters" : {
        "AvailabilityZone" : {
            "Default" : "us-east-1d",
            "Description" : "Enter AvailabilityZone.",
            "Type" : "String"
        },
        "VpcCidrBlock" : {
            "Default" : "10.0.0.0/16",
            "Description" : "VPC CIDR Block.",
            "Type" : "String"
        },
        "PublicSubnetCidrBlock" : {
            "Default" : "10.0.0.0/24",
            "Description" : "Public subnet CIDR block.",
            "Type" : "String"
        },
        "PrivateSubnetCidrBlock1" : {
            "Default" : "10.0.1.0/24",
            "Description" : "Private subnet CIDR block.",
            "Type" : "String"
        },
        "PrivateSubnetCidrBlock2" : {
            "Default" : "10.0.2.0/24",
            "Description" : "Private subnet CIDR block.",
            "Type" : "String"
        },
        "PrivateSubnetCidrBlock3" : {
            "Default" : "10.0.3.0/24",
            "Description" : "Private subnet CIDR block.",
            "Type" : "String"
        }
    },
    "Resources" : {
        "VpcStack" : {
            "Type" : "AWS::CloudFormation::Stack",
            "Properties" : {
                "Parameters" : {
                    "VpcCidrBlock" : {
                        "Ref" : "VpcCidrBlock"
                    }
                },
                "TemplateURL" : "https://s3.amazonaws.com/URLs/templates/vpcStack.json",
                "TimeoutInMinutes" : "5"
            }
        },
        "PrivateSubnetStack1" : {
            "Type" : "AWS::CloudFormation::Stack",
            "Properties" : {
                "Parameters" : {
                    "PrivateSubnetCidrBlock1" : {
                        "Ref" : "PrivateSubnetCidrBlock1"
                    },
                    "VpcStackName" : {
                        "Fn::GetAtt" : [
                            "VpcStack",
                            "Outputs.VpcStack"
                        ]
                    }
                },
                "TemplateURL" : "https://s3.amazonaws.com/URLs/templates/privateSubnetStack1.json",
                "TimeoutInMinutes" : "5"
            }
        },
        "PrivateSubnetStack2" : {
            "Type" : "AWS::CloudFormation::Stack",
            "Properties" : {
                "Parameters" : {
                    "PrivateSubnetCidrBlock2" : {
                        "Ref" : "PrivateSubnetCidrBlock2"
                    },
                    "VpcStackName" : {
                        "Fn::GetAtt" : [
                            "VpcStack",
                            "Outputs.VpcStack"
                        ]
                    }
                },
                "TemplateURL" : "https://s3.amazonaws.com/URLs/templates/privateSubnetStack2.json",
                "TimeoutInMinutes" : "5"
            }
        },
        "PrivateSubnetStack3" : {
            "Type" : "AWS::CloudFormation::Stack",
            "Properties" : {
                "Parameters" : {
                    "PrivateSubnetCidrBlock3" : {
                        "Ref" : "PrivateSubnetCidrBlock3"
                    },
                    "VpcStackName" : {
                        "Fn::GetAtt" : [
                            "VpcStack",
                            "Outputs.VpcStack"
                        ]
                    }
                },
                "TemplateURL" : "https://s3.amazonaws.com/URLs/templates/privateSubnetStack3.json",
                "TimeoutInMinutes" : "5"
            }
        },
        "PublicSubnetStack" : {
            "Type" : "AWS::CloudFormation::Stack",
            "Properties" : {
                "Parameters" : {
                    "PublicSubnetCidrBlock" : {
                        "Ref" : "PublicSubnetCidrBlock"
                    },
                    "VpcStackName" : {
                        "Fn::GetAtt" : [
                            "VpcStack",
                            "Outputs.VpcStack"
                        ]
                    }
                },
                "TemplateURL" : "https://s3.amazonaws.com/URLs/templates/publicSubnetStack.json",
                "TimeoutInMinutes" : "5"
            }
        },
        "InternetGatewayStack" : {
            "Type" : "AWS::CloudFormation::Stack",
            "Properties" : {
                "Parameters" : {
                    "VpcStackName" : {
                        "Fn::GetAtt" : [
                            "VpcStack",
                            "Outputs.VpcStack"
                        ]
                    }
                },
                "TemplateURL" : "https://s3.amazonaws.com/URLs/templates/internetGatewayStack.json",
                "TimeoutInMinutes" : "5"
            }
        },
        "PublicRouteStack" : {
            "Type" : "AWS::CloudFormation::Stack",
            "Properties" : {
                "Parameters" : {
                    "VpcStackName" : {
                        "Fn::GetAtt" : [
                            "VpcStack",
                            "Outputs.VpcStack"
                        ]
                    },
                    "PublicSubnetStackName" : {
                        "Fn::GetAtt" : [
                            "PublicSubnetStack",
                            "Outputs.PublicSubnetStack"
                        ]
                    },
                    "InternetGatewayStackName" : {
                        "Fn::GetAtt" : [
                            "InternetGatewayStack",
                            "Outputs.InternetGatewayStack"
                        ]
                    }
                },
                "TemplateURL" : "https://s3.amazonaws.com/URLs/templates/publicRouteStack.json",
                "TimeoutInMinutes" : "5"
            }

        }
    }
}

公共子网:

{
    "AWSTemplateFormatVersion" : "2010-09-09",
    "Description" : "Public Subnet Stack",
    "Parameters" : {
        "PublicSubnetCidrBlock" : {
            "Description" : "Public subnet CIDR block.",
            "Type" : "String"
        },
        "VpcStackName" : {
            "Description" : "VPC Stack Name.",
            "Type" : "String"
        }
    },
    "Resources" : {
        "PublicSubnet" : {
            "Type" : "AWS::EC2::Subnet",
            "Properties" : {
                "VpcId" : {
                    "Fn::Sub" : "${VpcStackName}"
                },
                "CidrBlock" : {
                    "Ref" : "PublicSubnetCidrBlock"
                },
                "Tags" : [
                    {
                        "Key" : "Application",
                        "Value" : {
                            "Ref" : "AWS::StackName"
                        }
                    },
                    {
                        "Key" : "Network",
                        "Value" : "Public"
                    }
                ]
            }
        }
    },
    "Outputs" : {
        "PublicSubnetStack" : {
            "Description" : "Public Subnet ID.",
            "Value" : {
                "Ref" : "PublicSubnet"
            },
            "Export" : {
                "Name" : {
                    "Fn::Sub" : "${AWS::StackName}-PublicSubnet"
                }
            }
        }
    }
}

互联网网关:

{
    "AWSTemplateFormatVersion" : "2010-09-09",
    "Description" : "Internet Gateway",
    "Parameters" : {
        "VpcStackName" : {
            "Description" : "VPC Stack Name.",
            "Type" : "String"
        }
    },
    "Resources" : {
        "InternetGateway" : {
            "Type" : "AWS::EC2::InternetGateway",
            "Properties" : {
                "Tags" : [
                    {
                        "Key" : "Application",
                        "Value" : {
                            "Ref" : "AWS::StackId"
                        }
                    },
                    {
                        "Key" : "Network",
                        "Value" : "Public"
                    }
                ]
            }
        },
        "GatewayToInternet" : {
            "Type" : "AWS::EC2::VPCGatewayAttachment",
            "Properties" : {
                "VpcId" : {
                    "Fn::Sub" : "${VpcStackName}"
                },
                "InternetGatewayId" : {
                    "Ref" : "InternetGateway"
                }
            }
        }
    },
    "Outputs" : {
        "InternetGatewayStack" : {
            "Description" : "Internet Gateway ID.",
            "Value" : {
                "Ref" : "InternetGateway"
            },
            "Export" : {
                "Name" : {
                    "Fn::Sub" : "${AWS::StackName}-InternetGateway"
                }
            }
        }
    }
}

公共路线:

{
    "AWSTemplateFormatVersion" : "2010-09-09",
    "Description" : "Public Route Table",
    "Parameters" : {
        "VpcStackName" : {
            "Description" : "VPC Stack Name.",
            "Type" : "String"
        },
        "PublicSubnetStackName" : {
            "Description" : "Public Subnet Stack Name.",
            "Type" : "String"
        },
        "InternetGatewayStackName" : {
            "Description" : "Internet Gateway Stack Name.",
            "Type" : "String"
        }
    },
    "Resources" : {
        "PublicRouteTable" : {
            "Type" : "AWS::EC2::RouteTable",
            "Properties" : {
                "VpcId" : {
                    "Fn::Sub" : "${VpcStackName}"
                },
                "Tags" : [
                    {
                        "Key" : "Application",
                        "Value" : {
                            "Ref" : "AWS::StackId"
                        }
                    },
                    {
                        "Key" : "Network",
                        "Value" : "Public"
                    }
                ]
            }
        },
        "PublicRoute" : {
            "Type" : "AWS::EC2::Route",
            "Properties" : {
                "RouteTableId" : {
                    "Ref" : "PublicRouteTable"
                },
                "DestinationCidrBlock" : "0.0.0.0/0",
                "GatewayId" : {
                    "Fn::Sub" : "${InternetGatewayStackname}"
                }
            }
        },
        "PublicSubnetRouteTableAssociation" : {
            "Type" : "AWS::EC2::SubnetRouteTableAssociation",
            "Properties" : {
                "SubnetId" : {
                    "Fn::Sub" : "${PublicSubnetStackName}"
                },
                "RouteTableId" : {
                    "Ref" : "PublicRouteTable"
                }
            }
        }
    },
    "Outputs" : {
        "PublicRoute" : {
            "Description" : "Public Route.",
            "Value" : {
                "Ref" : "PublicRoute"
            },
            "Export" : {
                "Name" : {
                    "Fn::Sub" : "${AWS::StackName}-PublicRoute"

                }
            }
        }
    }
}

谢谢!

1 个答案:

答案 0 :(得分:1)

您的资源名为InternetGatewayStackName

但在您的PublicRoute资源中,您使用的是以下内容:

"Fn::Sub" : "${InternetGatewayStackname}"

请注意,sub中的大小写与资源名称中的大小写不匹配。