dongya5893
2019-03-29 19:16
采纳率: 100%
浏览 70
已采纳

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

I am having trouble writing a script in Golang to launch a cloudformation template that has several parameters. I am new to both sdk and golang, so I am running into several syntax errors.

I have tried running the code in 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"),
    })
}

Error code:

./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
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douguazhi5966 2019-03-29 19:19
    已采纳

    You're trying to provide a []Parameter containing a single Parameter object with duplicate fields (as the error says) where you need a. You need to pass a []*Parameter containing a pointer for each parameter you want to pass, all in the slice:

        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"),
            },
        },
    

    (It looks like you also have main declared twice in another file, but that source isn't shown and the error is unrelated.)

    点赞 打赏 评论

相关推荐 更多相似问题