本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/cloudformation.CloudFormation类的典型用法代码示例。如果您正苦于以下问题:Golang CloudFormation类的具体用法?Golang CloudFormation怎么用?Golang CloudFormation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CloudFormation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例2: destroyStack
func destroyStack(svc *cloudformation.CloudFormation, name string) error {
dreq := &cloudformation.DeleteStackInput{
StackName: aws.String(name),
}
_, err := svc.DeleteStack(dreq)
return err
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
示例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
}
示例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]))
}
}
示例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)
}
示例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
}
示例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
}
示例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)
}
}
示例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))
}
示例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
}
示例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)
}