1

我正在尝试实现相同的目标,但对于 Parameter Store。我的场景是,开发人员将提供一个带有键/值的 .json 文件。CloudFormation 模板应使用该文件根据作为 json 文件创建的条目创建 Parameter Store 资源。

主模板 -

    {
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
    "SSMParameterStore": {
        "Description": "SSM Parameter Store",
        "Type": "String"
    }
},
"Resources": {
        "InputParameters": {
            "Type": "AWS::SSM::Parameter",
            "Properties": {
                "Name": {"Ref": "ParameterKey"},
                "Type": "String",
                "Value": {"Ref": "ParameterValue"}
            }
        }
    }
}

输入模板 -

[{
"ParameterKey": "KeyPairName",
"ParameterValue": "MyKey"
},
{
"ParameterKey": "InstanceType",
"ParameterValue": "m1.micro"
}
]

命令:

aws cloudformation create-stack --stack-name test --template-body file:///home/user/Documents/Work/training/test/templt.json --parameters file:///home/user/Documents/Work/training/test/test.json --region us-east-1

输出:

An error occurred (ValidationError) when calling the CreateStack operation: Parameters: [SSMParameterStore] must have values

不确定这里缺少什么。

4

2 回答 2

2

您的模板有一个参数,SSMParameterStore但您正在传入KeyPairNameand InstanceType

于 2020-02-18T14:29:03.847 回答
0

以一点进步回答我自己的帖子。

下面是工作模板。

主模板 -

    {
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
    "KeyPairName": {
        "Description": "ssm key",
        "Type": "String"
    },
    "KeyPairValue": {
        "Description": "Value",
        "Type": "String"
    },
    "KeyPairName1": {"Description": "ssm key", "Type": "String"},
    "KeyPairValue1": {"Description": "ssm key", "Type": "String"}
},

"Resources": {
        "InputParameters": {
            "Type": "AWS::SSM::Parameter",
            "Properties": {
                "Name": {"Ref": "KeyPairName"},
                "Type": "String",
                "Value": {"Ref": "KeyPairValue"}
            }
    },
        "InputParamters": {
        "Type": "AWS::SSM::Parameter",
        "Properties": {
            "Name": {"Ref": "KeyPairName1"},
            "Type": "String",
            "Value": {"Ref": "KeyPairValue1"}
        }
    }

}
}

参数模板 -

    [
    {
        "ParameterKey": "KeyPairName",
        "ParameterValue": "/config/dev/ms/FIRST_NAME"
        },
        {
        "ParameterKey": "KeyPairValue",
        "ParameterValue": "MY_F_NAME"
        },
        {
        "ParameterKey": "KeyPairName1",
        "ParameterValue": "/config/dev/ms/LAST_NAME"
        },
        {
        "ParameterKey": "KeyPairValue1",
        "ParameterValue": "MY_L_NAME"
        }

]

但问题是,每次参数模板文件中有新的键/值时,我都必须手动更新主模板。我仍然找不到动态执行此操作的方法,无论参数文件中的条目数量如何,我的模板都应采用所有键/值并在 Parameter Store 中创建/更新资源。似乎编写 Python 或 Bash 包装器可以做到这一点。

于 2020-02-21T05:33:52.023 回答