Skip to content

Latest commit

 

History

History
213 lines (144 loc) · 8.74 KB

README.md

File metadata and controls

213 lines (144 loc) · 8.74 KB

AWS SDK for Rust code examples for Amazon DynamoDB

Purpose

These examples demonstrate how to perform several Amazon DynamoDB (DynamoDB) operations using the developer preview version of the AWS SDK for Rust. Most use the schema defined in the create-table example.

DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability.

Code examples

⚠ Important

  • We recommend that you grant this code least privilege, or at most the minimum permissions required to perform the task. For more information, see Grant Least Privilege in the AWS Identity and Access Management User Guide.
  • This code has not been tested in all AWS Regions. Some AWS services are available only in specific Regions.
  • Running this code might result in charges to your AWS account.

Running the code examples

Prerequisites

You must have an AWS account, and have configured your default credentials and AWS Region as described in https://github.com/awslabs/aws-sdk-rust.

Running the code

add-item

This example adds a new item to the specified table.

cargo run --bin add-item -- -t TABLE -u USERNAME -p PERMISSION-TYPE -a AGE -f FIRST-NAME -l LAST-NAME [-r REGION] [-v]

  • TABLE is the name of the table to which the item is added.
  • USERNAME is the username of the user to add to the table. This is the key index to the table.
  • PERMISSION-TYPE is the type of user, either "standard_user" or "admin".
  • AGE is the age of the user.
  • FIRST-NAME is the first name of the user.
  • LAST-NAME is the last name of the user.
  • REGION is name of the AWS Region, such as us-east-1, where the table is located. If not supplied, uses the value of the AWS_REGION environment variable. If the environment variable is not set, defaults to us-west-2.
  • -v displays additional information.

are-more-tables

This example lists up to 10 tables, and if there are more tables, displays "There are more tables".

cargo run --bin are-more-tables -- [-r REGION] [-v]

  • REGION is name of the AWS Region, such as us-east-1, where the table is located. If not supplied, uses the value of the AWS_REGION environment variable. If the environment variable is not set, defaults to us-west-2.
  • -v displays additional information.

create-table

This example creates a table. Use delete-table to delete the table you've created.

cargo run --bin create-table -- -t TABLE -k KEY [-r REGION] [-v]

  • TABLE is the name of the table to which the item is added.
  • KEY is the primary key for the table.
  • REGION is name of the AWS Region, such as us-east-1, where the table is located. If not supplied, uses the value of the AWS_REGION environment variable. If the environment variable is not set, defaults to us-west-2.
  • -v displays additional information.

CRUD

This example creates a table, adds an item to the table, updates the item, deletes the item, and deletes the table.

cargo run --bin crud -- [-i] [-r REGION] [-v]

  • -i enables interactive mode, which pauses the code between operations.
  • REGION is name of the AWS Region, such as us-east-1, where the table is located. If not supplied, uses the value of the AWS_REGION environment variable. If the environment variable is not set, defaults to us-west-2.
  • -v displays additional information.

delete-item

This example deletes an item from a DynamoDB table.

cargo run --bin delete-item -- -t TABLE -k KEY -v VALUE [-r REGION] [-i]

  • TABLE is the name of the table containing the item to delete.
  • KEY is the name of the primary key of the item to delete.
  • VALUE is the value of the primary key of the item to delete.
  • REGION is name of the AWS Region, such as us-east-1, where the table is located. If not supplied, uses the value of the AWS_REGION environment variable. If the environment variable is not set, defaults to us-west-2.
  • -i displays additional information.

delete-table

This example deletes a DynamoDB table.

cargo run --bin delete-table -- -t TABLE [-r REGION] [-v]

  • TABLE is the name of the table to delete.
  • REGION is name of the AWS Region, such as us-east-1, where the table is located. If not supplied, uses the value of the AWS_REGION environment variable. If the environment variable is not set, defaults to us-west-2.
  • -v displays additional information.

dynamodb-helloworld

This example lists your DynamoDB tables and creates the table test-table. Use delete-table to delete test-table.

cargo run --bin dynamodb-helloworld

list10-tables

This example lists up to 10 of your DynamoDB tables.

cargo run --bin list10-tables -- [-r REGION] [-v]

  • REGION is name of the AWS Region, such as us-east-1, where the tables are located. If not supplied, uses the value of the AWS_REGION environment variable. If the environment variable is not set, defaults to us-west-2.
  • -v displays additional information.

list-items

This example lists the items in a DynamoDB table.

cargo run --bin list-items -- [-r REGION] [-v]

  • REGION is name of the AWS Region, such as us-east-1, where the tables are located. If not supplied, uses the value of the AWS_REGION environment variable. If the environment variable is not set, defaults to us-west-2.
  • -v displays additional information.

list-more-tables

This example lists your DynamoDB tables, and every 10 tables displays "-- more --".

cargo run --bin list-more-tables -- [-r REGION] [-v]

  • REGION is name of the AWS Region, such as us-east-1, where the tables are located. If not supplied, uses the value of the AWS_REGION environment variable. If the environment variable is not set, defaults to us-west-2.
  • -v displays additional information.

list-tables-local

This example lists your DynamoDB tables using LocalStack.

cargo run --bin list-tables-local

See the Localstack with the AWS SDK for Rust topic in the developer guide for details.

list-tables-main

This is a minimal example of listing your DynamoDB tables.

cargo run --bin list-tables-main

list-tables

This example lists your DynamoDB tables.

cargo run --bin list-tables -- [-r REGION] [-v]

  • REGION is name of the AWS Region, such as us-east-1, where the tables are located. If not supplied, uses the value of the AWS_REGION environment variable. If the environment variable is not set, defaults to us-west-2.
  • -v displays additional information.

movies

This example creates the DynamoDB table dynamo-movies-example_ in us-east-1, waits for the table to be ready, adds a couple of rows to the table, and queries for those rows. Use delete-table to delete dynamo-movies-example.

cargo run --bin movies

Resources

Contributing

To propose a new code example to the AWS documentation team, see CONTRIBUTING.md. The team prefers to create code examples that show broad scenarios rather than individual API calls.

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0