go/dynamodb/README.md
These examples demonstrates how to perform several DynamoDB operations.
You must have an AWS account, and have your default credentials and AWS Region configured as described in Configuring the AWS SDK for Go in the AWS SDK for Go Developer Guide.
This example creates a DynamoDB table.
go run CreateTable.go -t TABLE
The unit test accepts a similar value in config.json.
The table has two attributes:
Creates a new item in a DynamoDB table.
go run CreateTableItem -d TABLE -y YEAR -t TITLE -p PLOT -r RATING
The unit test accepts similar values in config.json.
This example deletes an item from a DynamoDB table.
go run DeleteTable.go -t TABLE -m MOVIE -y YEAR
The unit test mocks the DynamoDB service and the DeleteItem function.
This example retrieves an item from a DynamoDB table.
go run GetItem.go -t TABLE -n NAME -y YEAR
The unit test mocks the DynamoDB service and GetItem function.
This example lists your DynamoDB tables.
go run ListTables.go [-l LIMIT]
The unit test accepts a similar value in config.json.
This example adds items from a JSON file to a table.
go run LoadTableItems.go -j JSON-FILE -d TABLE
The unit test accepts similar values in config.json.
This example uses the Expression Builder package to scan a table for items that fit the criteria.
go run ScanItems.go -t TABLE -r RATING -y YEAR
The unit test mocks the DynamoDB service and Scan function.
This example updates the year and rating of a movie in a table.
go run UpdateItem.go -t TABLE -m MOVIE -y YEAR -r RATING
The unit test accepts similar values from config.json.
Unit tests should delete any resources they create. However, they might result in charges to your AWS account.
To run a unit test, enter:
go test
You should see something like the following, where PATH is the path to the folder containing the Go files:
PASS
ok PATH 6.593s
If you want to see any log messages, enter:
go test -test.v
You should see some additional log messages. The last two lines should be similar to the previous output shown.
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0