将Golang与AWS开发工具包Cloudformation一起使用到CreateChangeSet()并难以确定此ValidationError的原因:
error on CreateChangeSet: ValidationError:
StackName must be specified if ChangeSetName is not specified as an ARN.
status code: 400
有人知道执行变更集时如何克服此验证错误吗?
changesetName := `some_unique_value_<timestamp>`
stackARN := `arn:aws:cloudformation:us-west-2:<accountID>:stack/sample-stack1/<GUID>`
changesetName := instance.GetChangeSetName() // example:
CreateChangeSetInput := &cloudformation.CreateChangeSetInput{
StackName: aws.String(stackARN), // required field.
ChangeSetName: aws.String(changesetName), // must be a unique value
ChangeSetType: aws.String("UPDATE"), // stack exists. using UPDATE
TemplateBody: aws.String(templateBody), // cfn template
Parameters: params} // cfn paramaters
// Issue AWS CreateChangeSet API call
log.Println("Issuing AWS CreateChangeSet() API call")
_, err = svc.CreateChangeSet(CreateChangeSetInput)
if err != nil {
return fmt.Errorf("Got error on CreateChangeSet: %v", err.Error())
}
ExecuteChangeSetInput := &cloudformation.ExecuteChangeSetInput{
ChangeSetName: aws.String(changesetName)}
// Issue AWS CreateChangeSet API call
log.Println("Issuing AWS CreateChangeSet() API call")
_, err = svc.ExecuteChangeSet(ExecuteChangeSetInput)
if err != nil {
return fmt.Errorf("Got error on CreateChangeSet: %v", err.Error())
}
答案 0 :(得分:0)
发布后仅几分钟,我意识到该错误实际上是来自第二个api调用。在ExecuteChangeSet调用中提供相同的StackName可解决验证错误:
ExecuteChangeSetInput := &cloudformation.ExecuteChangeSetInput{
ChangeSetName: aws.String(changesetName),
StackName: aws.String(stackARN)}