Skip to content

Latest commit

 

History

History
254 lines (177 loc) · 10.3 KB

README.md

File metadata and controls

254 lines (177 loc) · 10.3 KB

AWS SDK for Rust code examples for Amazon S3

Purpose

These examples demonstrate how to perform several Amazon Simple Storage Service (Amazon S3) operations using the developer preview version of the AWS SDK for Rust.

Amazon S3 is storage for the internet. You can use Amazon S3 to store and retrieve any amount of data at any time, from anywhere on the web.

Code examples

Scenario examples

API 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.

Prerequisites

You must have an AWS account, and have configured your default credentials and AWS Region as described in the Getting Started section of the SDK README. The minimum version of Rust needed to run the SDK is listed here. Instructions for installing Rust and Cargo can be found in the Official Rust Documentation.

Running the code examples

Getting started with buckets and objects

Automatically demonstrates how to create a bucket, upload and download objects, and cleans everything up. To start, run the following at a command prompt from the Rust root of the project:

cargo run --bin s3-getting-started

Or, to run the test suite for the associated S3 library, run this command from the Rust root of the project:

cargo test -p s3_code_examples --test test-s3-getting-started

client

This example creates a basic client and lists your Amazon S3 buckets.

cargo run --bin client -- [-r REGION] [-v]

  • REGION is 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.

copy-object

This example copies an object from one Amazon S3 bucket to another.

cargo run --bin copy-object -- -s SOURCE-BUCKET -d DESTINATION-BUCKET -k KEY [-n NEW-NAME] [-r REGION] [-v]

  • SOURCE-BUCKET is the name of the bucket containing the object to copy.
  • DESTINATION-BUCKET is the name of the bucket where the object is copied to.
  • KEY is the name of the object to copy.
  • NEW-NAME is the optioal name of the object in the destination bucket. If not supplied, defaults to the value of KEY.

create-bucket

This example creates an Amazon S3 bucket.

cargo run --bin create-bucket -- -b BUCKET [-r REGION] [-v]

  • BUCKET is the name of the bucket to create.
  • REGION is 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.

delete-object

This example deletes an object from an Amazon S3 bucket.

cargo run --bin delete-object -- -b BUCKET -k KEY [-r REGION] [-v]

  • BUCKET is the name of the bucket.
  • KEY is the name of the object.
  • REGION is 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.

delete-objects

This example deletes one or more objects from an Amazon S3 bucket.

cargo run --bin delete-objects -- -b BUCKET -o OBJECTS [-r REGION] [-v]

  • BUCKET is the name of the bucket.
  • OBJECTS are the names of the objects to delete, separated by spaces.
  • REGION is 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.

get-object-presigned

This example creates a public URI to an object in an Amazon S3 bucket.

cargo run --bin get-object-presigned -- -b BUCKET -o OBJECT [-e EXPIRES-IN] [-r REGION] [-v]

  • BUCKET is the name of the bucket.
  • OBJECT is the name of the object.
  • EXPIRES-IN is the duration, in seconds, that the URI is valid. The default is 900 (15 minutes).
  • REGION is 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.

list-buckets

This example lists your Amazon S3 buckets.

cargo run --bin list-buckets -- [-s] [-r REGION] [-v]

  • -s display only buckets in the Region.
  • REGION is 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.

list-objects

This example lists the objects in an Amazon S3 bucket.

cargo run --bin list-objects -- -b BUCKET [-r REGION] [-v]

  • BUCKET is the name of the bucket.
  • REGION is 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.

list-object-versions

This example lists the versions of the objects in an Amazon S3 bucket.

cargo run --bin list-objects -- -b BUCKET [-r REGION] [-v]

  • BUCKET is the name of the bucket.
  • REGION is 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.

put-object-presigned

This example uploads a file to an Amazon S3 bucket, creates a public URI to the object, and displays the URI.

cargo run --bin put-object-presigned -- -b BUCKET -o OBJECT [-e EXPIRES-IN] [-r REGION] [-v]

  • BUCKET is the name of the bucket.
  • OBJECT is the name of the file to upload to the bucket.
  • EXPIRES-IN is the duration, in seconds, that the URI is valid. The default is 900 (15 minutes).
  • REGION is 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.

s3-helloworld

This example lists your buckets and uploads a file to a bucket.

cargo run --bin s3-helloworld -- -b BUCKET -f FILENAME -k KEY [-r REGION] [-v]

  • BUCKET is the name of the bucket.
  • FILENAME is the name of the file to upload.
  • KEY is the name of the file to upload to the bucket.
  • REGION is 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.

s3-object-lambda

This example lists your buckets in a specified endpoint.

cargo run --bin s3-object-lambda -- -a ACCOUNT -e ENDPOINT [-r REGION] [-v]

  • ACCOUNT is the your account number.
  • ENDPOINT is the endpoint.
  • KEY is the name of the file to upload to the bucket.
  • REGION is 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.

The object must have the following format.

Name,PhoneNumber,City,Occupation
Person1,(nnn) nnn-nnnn,City1,Occupation1
...
PersonN,(nnn) nnn-nnnn,CityN,OccupationN

select-object-content.rs

This example uses an SQL query to retrive information from an object, in CSV format, in an Amazon S3 bucket.

cargo run --bin select-object-content -- -b BUCKET -o OBJECT -n NAME [-r REGION] [-v]

  • BUCKET is the name of the bucket.
  • OBJECT is the name of the object to query.
  • NAME is the name of the person to retrieve infomation about.

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