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.)

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

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)