MCPcopy Create free account
hub / github.com/awsdocs/aws-doc-sdk-examples / main

Function main

go/example_code/cloudformation/CfnCrudOps.go:77–156  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

75}
76
77func main() {
78 operationPtr := flag.String("o", "", "The operation to perform: create, list, delete, or all in that order")
79 stackNamePtr := flag.String("n", "", "The name of the stack to create or delete")
80 templateFilePtr := flag.String("t", "", "The name of the file containing the CloudFormation template")
81 flag.Parse()
82 operation := *operationPtr
83 stackName := *stackNamePtr
84 templateFile := *templateFilePtr
85
86 if (operation == "create" || operation == "delete" || operation == "all") && stackName == "" {
87 // Create dummy name using guid
88 // Create a unique GUID for stack name
89 id := uuid.New()
90 stackName = "stack-" + id.String()
91 }
92
93 if (operation == "create" || operation == "all") && templateFile == "" {
94 fmt.Println("You must supply the name of the template to use to create a stack")
95 return
96 }
97
98 // Initialize a session that the SDK uses to load
99 // credentials from the shared credentials file ~/.aws/credentials
100 // and configuration from the shared configuration file ~/.aws/config.
101 sess := session.Must(session.NewSessionWithOptions(session.Options{
102 SharedConfigState: session.SharedConfigEnable,
103 }))
104
105 switch operation {
106 case "all":
107 // Create stack
108 err := CreateStack(sess, stackName, templateFile)
109 if err != nil {
110 fmt.Println("Could not create stack " + stackName)
111 }
112
113 // Get all stacks
114 summaries, err := GetStackSummaries(sess, "all")
115 if err != nil {
116 fmt.Println("Could not list stack summary info")
117 return
118 }
119
120 for _, s := range summaries {
121 fmt.Println(*s.StackName + ", Status: " + *s.StackStatus)
122 }
123
124 fmt.Println("")
125
126 // Delete stack
127 err = DeleteStack(sess, stackName)
128 if err != nil {
129 fmt.Println("Could not delete stack " + stackName)
130 }
131 case "create":
132 err := CreateStack(sess, stackName, templateFile)
133 if err != nil {
134 fmt.Println("Could not create stack " + stackName)

Callers

nothing calls this directly

Calls 4

CreateStackFunction · 0.70
GetStackSummariesFunction · 0.70
DeleteStackFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected