First I apologice for my English and I advice I'm new to Go. I'm trying to get a list of all stackId's on my opsworks stacks, or to give the stackname like I did with the ruby sdk and get the stackid so I can use with another service calls, but for now im trying to get them all to get familiar with the sdk.
func main() {
svc := opsworks.New(session.New(&aws.Config{
Region: aws.String("us-east-1"),
Credentials: credentials.NewSharedCredentials("", "development"),
}))
resp, err := svc.DescribeStacks()
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(resp)
}
the reason I omitted "params" is because of this: http://docs.aws.amazon.com/sdk-for-go/api/service/opsworks.html#type-DescribeStacksInput that says: "An array of stack IDs that specify the stacks to be described. If you omit this parameter, DescribeStacks returns a description of every stack."
O keep getting or "not enough arguments in call to svc.DescribeStacks" or "alidationException: Please provide no arguments or, one or more stack IDs" or "!v(PANIC=reflect: call of reflect.Value.Interface on zero Value)"
So I'm trying many ways.. not just the one I pasted here.. thats why diff results... changing to () to (nil) etc.. to omit the parameters so I can get a list of all the stacks. Im sure is very silly, any idea? I have search in google etc but all examples are for ec2 or s3...
got a response that worked in the main github issues site.
I see thanks for clarifying. The example you listed in 180498284 is actually the best way to get a list of all of your stack Ids.
To retrieve the individual stack Ids from the response you use the fields of opsworks.DescribeStacksOutput struct. This struct has a field Stacks which is a list of opsworks.Stack structs. The StackId is a field on this struct.
resp, err := svc.DescribeStacks(nil)
if err != nil {
return err
}
for _, stack := range resp.Stacks {
stackName := aws.StringValue(stack.Name)
if stackName == owstackname {
fmt.Printf("found %s stackid
", stackName)
fmt.Println(aws.StringValue(stack.StackId))
}
}
The aws.StringValue functions are helpers to convert the string pointer types of the SDK's input/output structs to values. It also protects against the value being nil where it will return empty string.