如何获取cloudformation模板中的参数以使用Amazon Go SDK启动?

凯文:

我无法在Golang中编写脚本来启动具有多个参数的cloudformation模板。我是sdk和golang的新手,因此遇到了一些语法错误。

我试图在VS studio中运行代码。

func runCFTscript(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Type", "application/json")
    sess, err := session.NewSession(&aws.Config{
        Region: aws.String("us-west-1")},
    )

    // Create Cloudformation service client
    svc := cloudformation.New(sess)

    // Specify the details of the instance that you want to create.
    runResult, err := svc.CreateStack(&cloudformation.CreateStackInput{


        Parameters: []cloudformation.Parameter{
            {
                ParameterKey:   aws.String("Keyname"),
                ParameterValue: aws.String("testXXX"),
                ParameterKey:   aws.String("InstanceType"),
                ParameterValue: aws.String("t2.micro"),
                ParameterKey:   aws.String("SSHLocation"),
                ParameterValue: aws.String("0.0.0.0/0"),
            },
        },
        StackName:   aws.String("test"),
        TemplateURL: aws.String("https://test.com"),
    })
}

错误代码:

./cloudformation.go:27:3: cannot use []cloudformation.Parameter literal (type []cloudformation.Parameter) as type []*cloudformation.Parameter in field value
./cloudformation.go:31:5: duplicate field name in struct literal: ParameterKey
./cloudformation.go:32:5: duplicate field name in struct literal: ParameterValue
./cloudformation.go:33:5: duplicate field name in struct literal: ParameterKey
./cloudformation.go:34:5: duplicate field name in struct literal: ParameterValue
./main.go:55:6: main redeclared in this block
阿德里安:

您尝试在需要的地方提供一个[]Parameter包含Parameter重复字段的单一对象(如错误所示)。您需要为要传递的每个参数传递一个[]*Parameter包含指针的指针,所有指针都位于切片中:

    Parameters: []*cloudformation.Parameter{
        &cloudformation.Parameter{
            ParameterKey:   aws.String("Keyname"),
            ParameterValue: aws.String("testXXX"),
        },
        &cloudformation.Parameter{
            ParameterKey:   aws.String("InstanceType"),
            ParameterValue: aws.String("t2.micro"),
        },
        &cloudformation.Parameter{
            ParameterKey:   aws.String("SSHLocation"),
            ParameterValue: aws.String("0.0.0.0/0"),
        },
    },

(看起来您也已main在另一个文件中声明了两次,但未显示该源,并且该错误与之无关。)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章