嵌套的cloudformation堆栈中的资源依赖性问题

时间:2018-04-16 12:41:05

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

当我尝试使用新的嵌套堆栈更新我的根堆栈时,我收到错误。

错误:"模板格式错误:模板的资源块中未解决的资源依赖关系[ProjectsusgetFinancialsLF]"。

以下是我将值从我的主堆栈传递到嵌套堆栈的方式:

    "Resources": {
    "FinancialStack": {
        "Type": "AWS::CloudFormation::Stack",
        "Properties": {
            "TemplateURL": "https://s3.amazonaws.com/example/child-cft.json",
            "TimeoutInMinutes": "10",
            "Parameters": {
                "DBuser": {
                    "Ref": "DBuser"
                },
                "testDB": {
                    "Fn::GetAtt": [
                        "testDB",
                        "Endpoint.Address"
                    ]
                },
                "DBname": {
                    "Ref": "DBname"
                },
                "DBpass": {
                    "Ref": "DBpass"
                },
                "EnvType": {
                    "Ref": "EnvType"
                },
                "LambdaExecution": {
                    "Fn::GetAtt": [
                        "LambdaExecutionRole",
                        "Arn"
                    ]
                },
                "ApiGatewayRestApi": {
                    "Ref": "ApiGatewayRestApi"
                },
                "AuthorizerFuncApiGateway": {
                    "Ref": "AuthorizerFuncApiGatewayAuthorizer"
                },
                "ApiGatewayResourcePortfoliosPortfolioidVarProjectsProjectidVar" : {
                    "Ref": "ApiGatewayResourcePortfoliosPortfolioidVarProjectsProjectidVar"
                }
            }
        },
        "DependsOn": [
            "testDB",
            "LambdaExecutionRole",
            "AuthorizerFuncApiGatewayAuthorizer",
            "ApiGatewayResourcePortfoliosPortfolioidVarProjectsProjectidVar"
        ]
    }

这是我的子堆栈以及抛出错误的函数:

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS CloudFormation to generate test one shot deployment",
"Parameters": {
    "DBuser": {
        "Type": "String"
    },
    "testDB": {
        "Type": "String"
    },
    "DBname": {
        "Type": "String"
    },
    "DBpass": {
        "Type": "String"
    },
    "EnvType": {
        "Type": "String"
    },
    "LambdaExecution": {
        "Type": "String"
    },
    "ApiGatewayRestApi": {
        "Type": "String"
    },
    "AuthorizerFuncApiGateway": {
        "Type": "String"
    },
    "ApiGatewayResourcePortfoliosPortfolioidVarProjectsProjectidVar": {
        "Type": "String"
    }
},
"Resources": {
    "ProjectsusgetProjectFinancialsLF": {
        "Type": "AWS::Lambda::Function",
        "Properties": {
            "Code": {
                "S3Bucket": "dev",
                "S3Key": "test-lamda.zip",
                "S3ObjectVersion": "9eNYbcI5EOuuut9igX2xpgbGCtKD1D4K"
            },
            "Environment": {
                "Variables": {
                    "MYSQLDB_USER": {
                        "Ref": "DBuser"
                    },
                    "MYSQLDB_HOST": {
                        "Ref": "testDB"
                    },
                    "MYSQLDB_DATABASE": {
                        "Ref": "DBname"
                    },
                    "MYSQLDB_PASSWORD": {
                        "Ref": "DBpass"
                    }
                }
            },
            "Description": "A get project financials function",
            "FunctionName": {
                "Fn::Join": [
                    "-",
                    [
                        {
                            "Ref": "EnvType"
                        },
                        "getProjectFinancials"
                    ]
                ]
            },
            "Handler": "src/controllers/projects.getProjectFinancials",
            "Role": {
                "Ref": "LambdaExecution"
            },
            "Runtime": "nodejs6.10"
        }
    },

我不确定为什么[ProjectsusgetFinancialsLF]有未解决的依赖项。我觉得我已经提供了该功能所需的一切。我无法弄清问题是什么。有人可以向我解释出现了什么问题吗?

编辑:在根堆栈中包含testDB资源

"       "testDB": {
        "Type": "AWS::RDS::DBInstance",
        "Properties": {
            "DBName": {
                "Ref": "DBname"
            },
            "DBSecurityGroups": [
                {
                    "Ref": "DBSecurityGroup"
                }
            ],
            "AllocatedStorage": "5",
            "DBInstanceClass": "db.t2.micro",
            "DBInstanceIdentifier": "testinst",
            "Engine": "MySQL",
            "EngineVersion": "5.7",
            "MasterUsername": {
                "Ref": "DBuser"
            },
            "MasterUserPassword": {
                "Ref": "DBpass"
            },
            "DBParameterGroupName": {
                "Ref": "RDSDBParameterGroup"
            }
        }
    },"

1 个答案:

答案 0 :(得分:3)

这可能是因为在您的根堆栈中引用epmoliteDB时,您并未声明它是来自另一个嵌套堆栈的输出。例如它应该看起来像。

                    "LambdaExecution": {
                    "Fn::GetAtt" : [ "epmoliteDB", "Outputs.Address" ] 
                }

我也是在epmoliteDB中假设输出正确的信息。在这种情况下,一个名为Address

的值

你可以在这里找到一些很好的例子 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-cloudformation.html

同样在参数部分的旁注中,当您将DBpass表示为String时,您还要添加NoEcho属性并将其设置为true。这将使您的密码在输入和更新堆栈时无法以纯文本形式查看。有关详细信息,请参阅https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html并转至NoEcho

相关问题