Skip to content

Latest commit

 

History

History
67 lines (45 loc) · 2.67 KB

README.md

File metadata and controls

67 lines (45 loc) · 2.67 KB

Testing AWS SDK for Rust code examples

Purpose

These examples demonstrate how to create a unit test for a Rust SDK operation. It uses the Amazon Simple Storage Service (Amazon S3) ListObjectsV2 operation to accumulate the size, in bytes, of objects in a bucket with a specified prefix, and shows how to mock the call using traits or an enum.

Code example

⚠ 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 example

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.

intro

This example gets the accumulated size, in bytes, of the objects with a specified prefix in a bucket.

cargo run -- -b BUCKET -p PREFIX [-r REGION] [-v]

  • BUCKET is the name of the bucket.
  • PREFIX is the first part of the bucket name.
  • REGION is name of the Region in which the client is created. 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.

Running the unit tests

There are four unit tests, two with the same name in enums.rs and two in traits.rs.

You can run all of the tests with the following command:

cargo test

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