|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX - License - Identifier: Apache - 2.0 |
| 3 | +// snippet-start:[dynamodb.gov2.DescribeTable] |
1 | 4 | package main
|
2 | 5 |
|
| 6 | +// snippet-start:[dynamodb.gov2.DescribeTable.imports] |
3 | 7 | import (
|
4 |
| - "context" |
5 |
| - "flag" |
6 |
| - "fmt" |
| 8 | + "context" |
| 9 | + "flag" |
| 10 | + "fmt" |
7 | 11 |
|
8 |
| - "github.com/aws/aws-sdk-go-v2/config" |
9 |
| - "github.com/aws/aws-sdk-go-v2/service/dynamodb" |
| 12 | + "github.com/aws/aws-sdk-go-v2/config" |
| 13 | + "github.com/aws/aws-sdk-go-v2/service/dynamodb" |
10 | 14 | )
|
| 15 | +// snippet-end:[dynamodb.gov2.DescribeTable.imports] |
11 | 16 |
|
12 |
| -// DynamoDBDescribeTableAPI defines the interface for DescribeTable function |
| 17 | +// DynamoDBDescribeTableAPI defines the interface for DescribeTable function. |
| 18 | +// snippet-start:[dynamodb.gov2.DescribeTable.interface] |
13 | 19 | type DynamoDBDescribeTableAPI interface {
|
14 |
| - DescribeTable(ctx context.Context, |
15 |
| - params *dynamodb.DescribeTableInput, |
16 |
| - optFns ...func(*dynamodb.Options)) (*dynamodb.DescribeTableOutput, error) |
| 20 | + DescribeTable(ctx context.Context, |
| 21 | + params *dynamodb.DescribeTableInput, |
| 22 | + optFns ...func(*dynamodb.Options)) (*dynamodb.DescribeTableOutput, error) |
17 | 23 | }
|
| 24 | +// snippet-end:[dynamodb.gov2.DescribeTable.interface] |
18 | 25 |
|
19 |
| -// GetTableInfo retrieves information about the tabl |
| 26 | +// GetTableInfo retrieves information about the table. |
| 27 | +// snippet-start:[dynamodb.gov2.DescribeTable.GetTableInfo] |
20 | 28 | func GetTableInfo(c context.Context, api DynamoDBDescribeTableAPI, input *dynamodb.DescribeTableInput) (*dynamodb.DescribeTableOutput, error) {
|
21 |
| - resp, err := api.DescribeTable(c, input) |
| 29 | + resp, err := api.DescribeTable(c, input) |
22 | 30 |
|
23 |
| - return resp, err |
| 31 | + return resp, err |
24 | 32 | }
|
| 33 | +// snippet-end:[dynamodb.gov2.DescribeTable.GetTableInfo] |
25 | 34 |
|
26 | 35 | func main() {
|
27 |
| - table := flag.String("t", "", "The name of the table") |
28 |
| - region := flag.String("r", "us-west-2", "The region") |
29 |
| - flag.Parse() |
30 |
| - |
31 |
| - if *table == "" { |
32 |
| - fmt.Println("You must specify a table name (-t TABLE)") |
33 |
| - return |
34 |
| - } |
35 |
| - |
36 |
| - // Using the SDK's default configuration, loading additional config |
37 |
| - // and credentials values from the environment variables, shared |
38 |
| - // credentials, and shared configuration files |
39 |
| - cfg, err := config.LoadDefaultConfig(config.WithRegion(*region)) |
40 |
| - if err != nil { |
41 |
| - panic("unable to load SDK config, " + err.Error()) |
42 |
| - } |
43 |
| - |
44 |
| - // Using the Config value, create the DynamoDB client |
45 |
| - // Create a new DynamoDB Service Client |
46 |
| - client := dynamodb.NewFromConfig(cfg) |
47 |
| - |
48 |
| - // Build the request with its input parameters |
49 |
| - resp, err := client.DescribeTable(context.Background(), &dynamodb.DescribeTableInput{ |
50 |
| - TableName: table, |
51 |
| - }) |
52 |
| - if err != nil { |
53 |
| - panic("failed to describe table, " + err.Error()) |
54 |
| - } |
55 |
| - |
56 |
| - fmt.Println("Info about " + *table + ":") |
57 |
| - fmt.Println(" #items: ", *resp.Table.ItemCount) |
58 |
| - fmt.Println(" Size (bytes)", *resp.Table.TableSizeBytes) |
59 |
| - fmt.Println(" Status: ", string(resp.Table.TableStatus)) |
| 36 | + // snippet-start:[dynamodb.gov2.DescribeTable.args] |
| 37 | + table := flag.String("t", "", "The name of the table") |
| 38 | + flag.Parse() |
| 39 | + |
| 40 | + if *table == "" { |
| 41 | + fmt.Println("You must specify a table name (-t TABLE)") |
| 42 | + return |
| 43 | + } |
| 44 | + // snippet-end:[dynamodb.gov2.DescribeTable.args] |
| 45 | + |
| 46 | + // snippet-start:[dynamodb.gov2.DescribeTable.config_and_client] |
| 47 | + // Use the SDK's default configuration. |
| 48 | + cfg, err := config.LoadDefaultConfig() |
| 49 | + if err != nil { |
| 50 | + panic("unable to load SDK config, " + err.Error()) |
| 51 | + } |
| 52 | + |
| 53 | + // Using the Config value, create the DynamoDB client |
| 54 | + // Create a new DynamoDB Service Client |
| 55 | + client := dynamodb.NewFromConfig(cfg) |
| 56 | + // snippet-end:[dynamodb.gov2.DescribeTable.config_and_client] |
| 57 | + |
| 58 | + // snippet-start:[dynamodb.gov2.DescribeTable.call] |
| 59 | + // Build the request with its input parameters |
| 60 | + resp, err := client.DescribeTable(context.Background(), &dynamodb.DescribeTableInput{ |
| 61 | + TableName: table, |
| 62 | + }) |
| 63 | + if err != nil { |
| 64 | + panic("failed to describe table, " + err.Error()) |
| 65 | + } |
| 66 | + // snippet-end:[dynamodb.gov2.DescribeTable.call] |
| 67 | + |
| 68 | + // snippet-start:[dynamodb.gov2.DescribeTable.print] |
| 69 | + fmt.Println("Info about " + *table + ":") |
| 70 | + fmt.Println(" #items: ", *resp.Table.ItemCount) |
| 71 | + fmt.Println(" Size (bytes)", *resp.Table.TableSizeBytes) |
| 72 | + fmt.Println(" Status: ", string(resp.Table.TableStatus)) |
| 73 | + // snippet-end:[dynamodb.gov2.DescribeTable.print] |
60 | 74 | }
|
| 75 | +// snippet-end:[dynamodb.gov2.DescribeTable] |
0 commit comments