func main()

in go/example_code/cloudformation/CfnCrudOps.go [88:167]


func main() {
    operationPtr := flag.String("o", "", "The operation to perform: create, list, delete, or all in that order")
    stackNamePtr := flag.String("n", "", "The name of the stack to create or delete")
    templateFilePtr := flag.String("t", "", "The name of the file containing the CloudFormation template")
    flag.Parse()
    operation := *operationPtr
    stackName := *stackNamePtr
    templateFile := *templateFilePtr

    if (operation == "create" || operation == "delete" || operation == "all") && stackName == "" {
        // Create dummy name using guid
        // Create a unique GUID for stack name
        id := uuid.New()
        stackName = "stack-" + id.String()
    }

    if (operation == "create" || operation == "all") && templateFile == "" {
        fmt.Println("You must supply the name of the template to use to create a stack")
        return
    }

    // Initialize a session that the SDK uses to load
    // credentials from the shared credentials file ~/.aws/credentials
    // and configuration from the shared configuration file ~/.aws/config.
    sess := session.Must(session.NewSessionWithOptions(session.Options{
        SharedConfigState: session.SharedConfigEnable,
    }))

    switch operation {
    case "all":
        // Create stack
        err := CreateStack(sess, stackName, templateFile)
        if err != nil {
            fmt.Println("Could not create stack " + stackName)
        }

        // Get all stacks
        summaries, err := GetStackSummaries(sess, "all")
        if err != nil {
            fmt.Println("Could not list stack summary info")
            return
        }

        for _, s := range summaries {
            fmt.Println(*s.StackName + ", Status: " + *s.StackStatus)
        }

        fmt.Println("")

        // Delete stack
        err = DeleteStack(sess, stackName)
        if err != nil {
            fmt.Println("Could not delete stack " + stackName)
        }
    case "create":
        err := CreateStack(sess, stackName, templateFile)
        if err != nil {
            fmt.Println("Could not create stack " + stackName)
        }
    case "list":
        summaries, err := GetStackSummaries(sess, "all")
        if err != nil {
            fmt.Println("Could not list stack summary info")
            return
        }

        for _, s := range summaries {
            fmt.Println(*s.StackName + ", Status: " + *s.StackStatus)
        }

        fmt.Println("")
    case "delete":
        err := DeleteStack(sess, stackName)
        if err != nil {
            fmt.Println("Could not delete stack " + stackName)
        }
    default:
        fmt.Println("Unrecognized operation: " + operation)
    }
}