Struct aws_manager::s3::Manager
source · [−]pub struct Manager { /* private fields */ }
Expand description
Implements AWS S3 manager.
Implementations
sourceimpl Manager
impl Manager
pub fn new(shared_config: &AwsSdkConfig) -> Self
pub fn client(&self) -> Client
sourcepub async fn create_bucket(&self, s3_bucket: &str) -> Result<()>
pub async fn create_bucket(&self, s3_bucket: &str) -> Result<()>
Creates a S3 bucket.
sourcepub async fn delete_bucket(&self, s3_bucket: &str) -> Result<()>
pub async fn delete_bucket(&self, s3_bucket: &str) -> Result<()>
Deletes a S3 bucket.
sourcepub async fn delete_objects(
&self,
s3_bucket: Arc<String>,
prefix: Option<Arc<String>>
) -> Result<()>
pub async fn delete_objects(
&self,
s3_bucket: Arc<String>,
prefix: Option<Arc<String>>
) -> Result<()>
Deletes objects by “prefix”. If “prefix” is “None”, empties a S3 bucket, deleting all files. ref. https://github.com/awslabs/aws-sdk-rust/blob/main/examples/s3/src/bin/delete-objects.rs
“If a single piece of data must be accessible from more than one task concurrently, then it must be shared using synchronization primitives such as Arc.” ref. https://tokio.rs/tokio/tutorial/spawning
sourcepub async fn list_objects(
&self,
s3_bucket: Arc<String>,
prefix: Option<Arc<String>>
) -> Result<Vec<Object>>
pub async fn list_objects(
&self,
s3_bucket: Arc<String>,
prefix: Option<Arc<String>>
) -> Result<Vec<Object>>
List objects in the bucket with an optional prefix, in the descending order of “last_modified” timestamps. “bucket_name” implies the suffix “/”, so no need to prefix sub-directory with “/”. Passing “bucket_name” + “directory” is enough!
e.g. “foo-mydatabucket” for bucket_name “mydata/myprefix/” for prefix
sourcepub async fn put_object(
&self,
file_path: Arc<String>,
s3_bucket: Arc<String>,
s3_key: Arc<String>
) -> Result<()>
pub async fn put_object(
&self,
file_path: Arc<String>,
s3_bucket: Arc<String>,
s3_key: Arc<String>
) -> Result<()>
Writes an object to a S3 bucket using stream.
WARN: use stream! otherwise it can cause OOM – don’t do the following! “fs::read” reads all data onto memory “.body(ByteStream::from(contents))” passes the whole data to an API call
“If a single piece of data must be accessible from more than one task concurrently, then it must be shared using synchronization primitives such as Arc.” ref. https://tokio.rs/tokio/tutorial/spawning
sourcepub async fn get_object(
&self,
s3_bucket: Arc<String>,
s3_key: Arc<String>,
file_path: Arc<String>
) -> Result<()>
pub async fn get_object(
&self,
s3_bucket: Arc<String>,
s3_key: Arc<String>,
file_path: Arc<String>
) -> Result<()>
Downloads an object from a S3 bucket using stream.
WARN: use stream! otherwise it can cause OOM – don’t do the following! “aws_smithy_http::byte_stream:ByteStream.collect” reads all the data into memory “File.write_all_buf(&mut bytes)” to write bytes
“If a single piece of data must be accessible from more than one task concurrently, then it must be shared using synchronization primitives such as Arc.” ref. https://tokio.rs/tokio/tutorial/spawning