list_tables.go - AWS Code Sample


Lists your Amazon DynamoDB tables.

/* Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package main import ( "fmt" "" "" "" "" ) func main() { // Initialize a session in us-west-2 that the SDK will use to load // credentials from the shared credentials file ~/.aws/credentials. sess, _ := session.NewSession(&aws.Config{ Region: aws.String("us-west-2")}, ) // Create DynamoDB client svc := dynamodb.New(sess) // create the input configuration instance input := &dynamodb.ListTablesInput{} fmt.Printf("Tables:\n") for { // Get the list of tables result, err := svc.ListTables(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case dynamodb.ErrCodeInternalServerError: fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) } return } for _, n := range result.TableNames { fmt.Println(*n) } // assign the last read tablename as the start for our next call to the ListTables function // the maximum number of table names returned in a call is 100 (default), which requires us to make // multiple calls to the ListTables function to retrieve all table names input.ExclusiveStartTableName = result.LastEvaluatedTableName if result.LastEvaluatedTableName == nil { break } } }

Sample Details

Service: dynamodb

Last tested: 2019-04-24

Author: Doug-AWS

Type: full-example