ListInstanceSnapshots.go - AWS Code Sample

ListInstanceSnapshots.go

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 package main import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rds" ) // GetInstanceSnapShots retrieves your Amazon RDS instance snapshots // Inputs: // sess is the current session, which provides configuration for the SDK's service clients // Output: // If success, the list of snapshots and nil // Otherwise, nil and an error from the call to DescribeDBSnapshots func GetInstanceSnapShots(sess *session.Session) (*rds.DescribeDBSnapshotsOutput, error) { svc := rds.New(sess) result, err := svc.DescribeDBSnapshots(nil) if err != nil { return nil, err } return result, nil } func main() { sess := session.Must(session.NewSessionWithOptions(session.Options{ SharedConfigState: session.SharedConfigEnable, })) result, err := GetInstanceSnapShots(sess) if err != nil { fmt.Println("Got an error retrieving instance snapshots:") fmt.Println(err) return } if len(result.DBSnapshots) < 1 { fmt.Println("Could not find any instance snapshots") return } for _, s := range result.DBSnapshots { fmt.Printf("* " + *s.DBSnapshotIdentifier + " with status " + *s.Status) } }