• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang cloudformation.CloudFormation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/cloudformation.CloudFormation的典型用法代码示例。如果您正苦于以下问题:Golang CloudFormation类的具体用法?Golang CloudFormation怎么用?Golang CloudFormation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了CloudFormation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: stackExists

// Does a given stack exist?
func stackExists(stackNameOrID string, cf *cloudformation.CloudFormation, logger *logrus.Logger) (bool, error) {
	describeStacksInput := &cloudformation.DescribeStacksInput{
		StackName: aws.String(stackNameOrID),
	}
	describeStacksOutput, err := cf.DescribeStacks(describeStacksInput)
	logger.WithFields(logrus.Fields{
		"DescribeStackOutput": describeStacksOutput,
	}).Debug("DescribeStackOutput results")

	exists := false
	if err != nil {
		logger.WithFields(logrus.Fields{
			"DescribeStackOutputError": err,
		}).Debug("DescribeStackOutput")

		// If the stack doesn't exist, then no worries
		if strings.Contains(err.Error(), "does not exist") {
			exists = false
		} else {
			return false, err
		}
	} else {
		exists = true
	}
	return exists, nil
}
开发者ID:dmreiland,项目名称:Sparta,代码行数:27,代码来源:provision.go


示例2: destroyStack

func destroyStack(svc *cloudformation.CloudFormation, name string) error {
	dreq := &cloudformation.DeleteStackInput{
		StackName: aws.String(name),
	}
	_, err := svc.DeleteStack(dreq)
	return err
}
开发者ID:colhom,项目名称:coreos-kubernetes,代码行数:7,代码来源:stack.go


示例3: stackEvents

// Return the StackEvents for the given StackName/StackID
func stackEvents(stackID string, cfService *cloudformation.CloudFormation) ([]*cloudformation.StackEvent, error) {
	var events []*cloudformation.StackEvent

	nextToken := ""
	for {
		params := &cloudformation.DescribeStackEventsInput{
			StackName: aws.String(stackID),
		}
		if len(nextToken) > 0 {
			params.NextToken = aws.String(nextToken)
		}

		resp, err := cfService.DescribeStackEvents(params)
		if nil != err {
			return nil, err
		}
		events = append(events, resp.StackEvents...)
		if nil == resp.NextToken {
			break
		} else {
			nextToken = *resp.NextToken
		}
	}
	return events, nil
}
开发者ID:dmreiland,项目名称:Sparta,代码行数:26,代码来源:provision.go


示例4: stackLambdaResources

func stackLambdaResources(serviceName string, cf *cloudformation.CloudFormation, logger *logrus.Logger) (provisionedResources, error) {

	resources := make(provisionedResources, 0)
	nextToken := ""
	for {
		params := &cloudformation.ListStackResourcesInput{
			StackName: aws.String(serviceName),
		}
		if "" != nextToken {
			params.NextToken = aws.String(nextToken)
		}
		resp, err := cf.ListStackResources(params)

		if err != nil {
			logger.Error(err.Error())
			return nil, err
		}
		for _, eachSummary := range resp.StackResourceSummaries {
			if *eachSummary.ResourceType == "AWS::Lambda::Function" {
				resources = append(resources, eachSummary)
			}
		}
		if nil != resp.NextToken {
			nextToken = *resp.NextToken
		} else {
			break
		}
	}
	return resources, nil
}
开发者ID:seiffert,项目名称:Sparta,代码行数:30,代码来源:explore.go


示例5: getCloudFormationFailures

// getCloudFormationFailures returns ResourceStatusReason(s)
// of events that should be failures based on regexp match of status
func getCloudFormationFailures(stackName *string, afterTime time.Time,
	conn *cloudformation.CloudFormation) ([]string, error) {
	var failures []string
	// Only catching failures from last 100 events
	// Some extra iteration logic via NextToken could be added
	// but in reality it's nearly impossible to generate >100
	// events by a single stack update
	events, err := conn.DescribeStackEvents(&cloudformation.DescribeStackEventsInput{
		StackName: stackName,
	})

	if err != nil {
		return nil, err
	}

	failRe := regexp.MustCompile("_FAILED$")
	rollbackRe := regexp.MustCompile("^ROLLBACK_")

	for _, e := range events.StackEvents {
		if (failRe.MatchString(*e.ResourceStatus) || rollbackRe.MatchString(*e.ResourceStatus)) &&
			e.Timestamp.After(afterTime) && e.ResourceStatusReason != nil {
			failures = append(failures, *e.ResourceStatusReason)
		}
	}

	return failures, nil
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:29,代码来源:resource_aws_cloudformation_stack.go


示例6: waitForCompletion

func waitForCompletion(stack string, CloudFormation *cloudformation.CloudFormation, isDeleting bool) (string, error) {
	for {
		dres, err := CloudFormation.DescribeStacks(&cloudformation.DescribeStacksInput{
			StackName: aws.String(stack),
		})

		if err != nil {
			stdcli.Error(err)
		}

		err = displayProgress(stack, CloudFormation, isDeleting)

		if err != nil {
			stdcli.Error(err)
		}

		if len(dres.Stacks) != 1 {
			stdcli.Error(fmt.Errorf("could not read stack status"))
		}

		switch *dres.Stacks[0].StackStatus {
		case "CREATE_COMPLETE":
			// Dump .env if DEVELOPMENT
			if isDevelopment {
				fmt.Printf("Development .env:\n")

				// convert Port5432TcpAddr to PORT_5432_TCP_ADDR
				re := regexp.MustCompile("([a-z])([A-Z0-9])") // lower case letter followed by upper case or number, i.e. Port5432
				re2 := regexp.MustCompile("([0-9])([A-Z])")   // number followed by upper case letter, i.e. 5432Tcp

				for _, o := range dres.Stacks[0].Outputs {
					k := re.ReplaceAllString(*o.OutputKey, "${1}_${2}")
					k = re2.ReplaceAllString(k, "${1}_${2}")
					k = strings.ToUpper(k)

					fmt.Printf("%v=%v\n", k, *o.OutputValue)
				}
			}

			for _, o := range dres.Stacks[0].Outputs {
				if *o.OutputKey == "Dashboard" {
					return *o.OutputValue, nil
				}
			}

			return "", fmt.Errorf("could not install stack, contact [email protected] for assistance")
		case "CREATE_FAILED":
			return "", fmt.Errorf("stack creation failed, contact [email protected] for assistance")
		case "ROLLBACK_COMPLETE":
			return "", fmt.Errorf("stack creation failed, contact [email protected] for assistance")
		case "DELETE_COMPLETE":
			return "", nil
		case "DELETE_FAILED":
			return "", fmt.Errorf("stack deletion failed, contact [email protected] for assistance")
		}

		time.Sleep(2 * time.Second)
	}
}
开发者ID:jjperezaguinaga,项目名称:rack,代码行数:59,代码来源:install.go


示例7: getLastCfEventTimestamp

// getLastCfEventTimestamp takes the first event in a list
// of events ordered from the newest to the oldest
// and extracts timestamp from it
// LastUpdatedTime only provides last >successful< updated time
func getLastCfEventTimestamp(stackName string, conn *cloudformation.CloudFormation) (
	*time.Time, error) {
	output, err := conn.DescribeStackEvents(&cloudformation.DescribeStackEventsInput{
		StackName: aws.String(stackName),
	})
	if err != nil {
		return nil, err
	}

	return output.StackEvents[0].Timestamp, nil
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:15,代码来源:resource_aws_cloudformation_stack.go


示例8: descStack

func descStack(svc *awscf.CloudFormation, stackName string) {
	input := &awscf.DescribeStackEventsInput{
		StackName: aws.String(stackName),
	}
	resp, err := svc.DescribeStackEvents(input)
	if err != nil {
		log.Fatal(err)
	}

	if len(resp.StackEvents) > 0 {
		log.Println(awsutil.StringValue(resp.StackEvents[0]))
	}
}
开发者ID:zeushammer,项目名称:cftool,代码行数:13,代码来源:main.go


示例9: cost

func cost(svc *awscf.CloudFormation, b []byte, params []*awscf.Parameter) {
	estInput := &awscf.EstimateTemplateCostInput{
		Parameters:   params,
		TemplateBody: aws.String(string(b)),
	}

	cost, err := svc.EstimateTemplateCost(estInput)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(*cost.URL)
}
开发者ID:zeushammer,项目名称:cftool,代码行数:13,代码来源:main.go


示例10: validateStack

func validateStack(svc *cloudformation.CloudFormation, stackBody string) (string, error) {

	input := &cloudformation.ValidateTemplateInput{
		TemplateBody: aws.String(stackBody),
	}

	validationReport, err := svc.ValidateTemplate(input)

	if err != nil {
		return "", fmt.Errorf("Invalid cloudformation stack: %v", err)
	}

	return validationReport.String(), err
}
开发者ID:colhom,项目名称:coreos-kubernetes,代码行数:14,代码来源:stack.go


示例11: deleteStack

func deleteStack(s Stack, distinctId string, CF *cloudformation.CloudFormation) error {
	deleteAttempts[s.StackName] += 1
	switch deleteAttempts[s.StackName] {
	case 1:
		fmt.Printf("Deleting %s...\n", s.Name)
	default:
		fmt.Printf("Retrying deleting %s...\n", s.Name)
	}

	_, err := CF.DeleteStack(&cloudformation.DeleteStackInput{
		StackName: aws.String(s.StackName),
	})
	return err
}
开发者ID:convox,项目名称:rack,代码行数:14,代码来源:uninstall.go


示例12: runUpsert

func (r *Run) runUpsert(client *cf.CloudFormation, d tacks.Document, stack string) error {

	e := d.Environment

	resp, _ := client.DescribeStacks(&cf.DescribeStacksInput{
		StackName: aws.String(e.StackName),
	})

	if len(resp.Stacks) == 0 {
		return r.runCreate(client, d, stack)
	} else {
		return r.runUpdate(client, d, stack)
	}

}
开发者ID:inka,项目名称:tacks,代码行数:15,代码来源:run.go


示例13: delStack

func delStack(svc *awscf.CloudFormation, stackName string) {
	input := &awscf.DeleteStackInput{
		StackName: aws.String(stackName),
	}

	_, err := svc.DeleteStack(input)
	if err != nil {
		log.Fatal(err)
	}
	// the log.Println ends up looking like
	// 2015/06/04 16:55:36 {
	//
	// }
	//
	// log.Println(awsutil.StringValue(resp))
}
开发者ID:zeushammer,项目名称:cftool,代码行数:16,代码来源:main.go


示例14: getCloudFormationFailures

func getCloudFormationFailures(stackId string, conn *cloudformation.CloudFormation) ([]string, error) {
	var failures []string

	err := conn.DescribeStackEventsPages(&cloudformation.DescribeStackEventsInput{
		StackName: aws.String(stackId),
	}, func(page *cloudformation.DescribeStackEventsOutput, lastPage bool) bool {
		for _, e := range page.StackEvents {
			if cfStackEventIsFailure(e) {
				failures = append(failures, *e.ResourceStatusReason)
			}
		}
		return !lastPage
	})

	return failures, err
}
开发者ID:partamonov,项目名称:terraform,代码行数:16,代码来源:resource_aws_cloudformation_stack.go


示例15: updateStack

func updateStack(svc *cloudformation.CloudFormation, stackName, stackBody string) (string, error) {

	input := &cloudformation.UpdateStackInput{
		Capabilities: []*string{aws.String(cloudformation.CapabilityCapabilityIam)},
		StackName:    aws.String(stackName),
		TemplateBody: aws.String(stackBody),
	}

	updateOutput, err := svc.UpdateStack(input)

	if err != nil {
		return "", fmt.Errorf("Error updating cloudformation stack: %v", err)
	}

	return updateOutput.String(), waitForStackUpdateComplete(svc, *updateOutput.StackId)
}
开发者ID:colhom,项目名称:coreos-kubernetes,代码行数:16,代码来源:stack.go


示例16: WaitForStackOperationComplete

// WaitForStackOperationComplete is a blocking, polling based call that
// periodically fetches the stackID set of events and uses the state value
// to determine if an operation is complete
func WaitForStackOperationComplete(stackID string,
	pollingMessage string,
	awsCloudFormation *cloudformation.CloudFormation,
	logger *logrus.Logger) (*WaitForStackOperationCompleteResult, error) {

	result := &WaitForStackOperationCompleteResult{}

	// Poll for the current stackID state, and
	describeStacksInput := &cloudformation.DescribeStacksInput{
		StackName: aws.String(stackID),
	}
	for waitComplete := false; !waitComplete; {
		sleepDuration := time.Duration(11+rand.Int31n(13)) * time.Second
		time.Sleep(sleepDuration)

		describeStacksOutput, err := awsCloudFormation.DescribeStacks(describeStacksInput)
		if nil != err {
			// TODO - add retry iff we're RateExceeded due to collective access
			return nil, err
		}
		if len(describeStacksOutput.Stacks) <= 0 {
			return nil, fmt.Errorf("Failed to enumerate stack info: %v", *describeStacksInput.StackName)
		}
		result.stackInfo = describeStacksOutput.Stacks[0]
		switch *(result.stackInfo).StackStatus {
		case cloudformation.StackStatusCreateComplete,
			cloudformation.StackStatusUpdateComplete:
			result.operationSuccessful = true
			waitComplete = true
		case
			// Include DeleteComplete as new provisions will automatically rollback
			cloudformation.StackStatusDeleteComplete,
			cloudformation.StackStatusCreateFailed,
			cloudformation.StackStatusDeleteFailed,
			cloudformation.StackStatusRollbackFailed,
			cloudformation.StackStatusRollbackComplete,
			cloudformation.StackStatusUpdateRollbackComplete:
			result.operationSuccessful = false
			waitComplete = true
		default:
			logger.Info(pollingMessage)
		}
	}
	return result, nil
}
开发者ID:mweagle,项目名称:Sparta,代码行数:48,代码来源:util.go


示例17: waitForCompletion

func waitForCompletion(stack string, CloudFormation *cloudformation.CloudFormation, isDeleting bool) (string, error) {
	for {
		dres, err := CloudFormation.DescribeStacks(&cloudformation.DescribeStacksInput{
			StackName: aws.String(stack),
		})
		if err != nil {
			return "", err
		}

		err = displayProgress(stack, CloudFormation, isDeleting)
		if err != nil {
			return "", err
		}

		if len(dres.Stacks) != 1 {
			return "", fmt.Errorf("could not read stack status")
		}

		switch *dres.Stacks[0].StackStatus {
		case "CREATE_COMPLETE":
			for _, o := range dres.Stacks[0].Outputs {
				if *o.OutputKey == "Dashboard" {
					return *o.OutputValue, nil
				}
			}

			stdcli.QOSEventSend("cli-install", distinctID, stdcli.QOSEventProperties{Error: err})
			return "", fmt.Errorf("could not install stack, contact [email protected] for assistance")
		case "CREATE_FAILED":
			stdcli.QOSEventSend("cli-install", distinctID, stdcli.QOSEventProperties{Error: err})
			return "", fmt.Errorf("stack creation failed, contact [email protected] for assistance")
		case "ROLLBACK_COMPLETE":
			stdcli.QOSEventSend("cli-install", distinctID, stdcli.QOSEventProperties{Error: err})
			return "", fmt.Errorf("stack creation failed, contact [email protected] for assistance")
		case "DELETE_COMPLETE":
			stdcli.QOSEventSend("cli-install", distinctID, stdcli.QOSEventProperties{Error: err})
			return "", nil
		case "DELETE_FAILED":
			stdcli.QOSEventSend("cli-install", distinctID, stdcli.QOSEventProperties{Error: err})
			return "", fmt.Errorf("stack deletion failed, contact [email protected] for assistance")
		}

		time.Sleep(2 * time.Second)
	}
}
开发者ID:convox,项目名称:rack,代码行数:45,代码来源:install.go


示例18: provisionStack

func provisionStack(svc *awscf.CloudFormation, b []byte, onFailure string, params []*awscf.Parameter, stackName string) {
	input := &awscf.CreateStackInput{
		StackName: aws.String(stackName),
		Capabilities: []*string{
			aws.String("CAPABILITY_IAM"),
		},
		OnFailure:        aws.String(onFailure),
		Parameters:       params,
		TemplateBody:     aws.String(string(b)),
		TimeoutInMinutes: aws.Long(20),
	}
	resp, err := svc.CreateStack(input)
	if err != nil {
		log.Fatal(err)
	}

	log.Println(awsutil.StringValue(resp))
}
开发者ID:zeushammer,项目名称:cftool,代码行数:18,代码来源:main.go


示例19: runCreate

func (r *Run) runCreate(client *cf.CloudFormation, d tacks.Document, stack string) error {

	e := d.Environment

	tacks.Logger().Infof("Creating stack %s", e.StackName)

	var (
		capabilities     []*string
		onFailure        = "DO_NOTHING"
		tags             []*cf.Tag
		timeoutInMinutes uint8 = 15
	)

	if d.IsIamCapabilitiesRequired() {
		capabilities = append(capabilities, aws.String("CAPABILITY_IAM"))
	}

	if e.DeleteOnFailure {
		onFailure = "DELETE"
	}

	if e.Timeout > 0 {
		timeoutInMinutes = e.Timeout
	}

	for key, value := range e.Tags {
		tags = append(tags, &cf.Tag{
			Key:   aws.String(key),
			Value: aws.String(value),
		})
	}

	_, err := client.CreateStack(&cf.CreateStackInput{
		Capabilities:     capabilities,
		OnFailure:        aws.String(onFailure),
		StackName:        aws.String(e.StackName),
		Tags:             tags,
		TemplateBody:     aws.String(stack),
		TimeoutInMinutes: aws.Long(int64(timeoutInMinutes)),
	})

	return err

}
开发者ID:inka,项目名称:tacks,代码行数:44,代码来源:run.go


示例20: createStackAndWait

func createStackAndWait(svc *cloudformation.CloudFormation, name, stackBody string) error {
	creq := &cloudformation.CreateStackInput{
		StackName:    aws.String(name),
		OnFailure:    aws.String("DO_NOTHING"),
		Capabilities: []*string{aws.String(cloudformation.CapabilityCapabilityIam)},
		TemplateBody: aws.String(stackBody),
	}

	resp, err := svc.CreateStack(creq)
	if err != nil {
		return err
	}

	if err := waitForStackCreateComplete(svc, aws.StringValue(resp.StackId)); err != nil {
		return err
	}

	return nil
}
开发者ID:colhom,项目名称:coreos-kubernetes,代码行数:19,代码来源:stack.go



注:本文中的github.com/aws/aws-sdk-go/service/cloudformation.CloudFormation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang cloudformation.CreateStackInput类代码示例发布时间:2022-05-24
下一篇:
Golang cloudformation.New函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap