forked from awsdocs/aws-doc-sdk-examples
/
ListParameterGroups.go
57 lines (48 loc) · 1.79 KB
/
ListParameterGroups.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
// snippet-start:[rds.go.list_parameter_groups]
package main
// snippet-start:[rds.go.list_parameter_groups.imports]
import (
"fmt"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/rds"
)
// snippet-end:[rds.go.list_parameter_groups.imports]
// GetParameterGroups retrieves your Amazon RDS parameter groups
// Inputs:
// sess is the current session, which provides configuration for the SDK's service clients
// Output:
// If success, a list of the parameter groups and nil
// Otherwise, nil and an error from the call to DescribeDBParameterGroups
func GetParameterGroups(sess *session.Session) (*rds.DescribeDBParameterGroupsOutput, error) {
// snippet-start:[rds.go.list_parameter_groups.call]
svc := rds.New(sess)
result, err := svc.DescribeDBParameterGroups(nil)
// snippet-end:[rds.go.list_parameter_groups.call]
if err != nil {
return nil, err
}
return result, nil
}
func main() {
// snippet-start:[rds.go.list_parameter_groups.session]
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
// snippet-end:[rds.go.list_parameter_groups.session]
result, err := GetParameterGroups(sess)
if err != nil {
fmt.Println("Got an error retrieving parameter groups:")
fmt.Println(err)
return
}
if len(result.DBParameterGroups) < 1 {
fmt.Println("Could not find any parameter groups")
return
}
for _, p := range result.DBParameterGroups {
fmt.Println("* " + *p.DBParameterGroupName + " with description: " + *p.Description)
}
}
// snippet-end:[rds.go.list_parameter_groups]