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

如何获取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.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能