Skip to content

Mock S3 "Custom" endpoint/region for local testing purposes? #253

Answered by rcoh
brainstorm asked this question in Q&A
Discussion options

You must be logged in to vote

Hello! using s3-server is a totally reasonable testing strategy, you can accomplish by setting a custom endpoint:
(note that you'll need to a dependency on http directly and construct your client a little differently):

use aws_sdk_s3::Client;
use aws_sdk_s3::Endpoint;
use http::Uri;

#[tokio::main]
async fn main() {
    let conf = aws_config::load_from_env().await;
    let ep = Endpoint::immutable(Uri::from_static("http://localhost:8543"));
    let s3_conf = aws_sdk_s3::config::Builder::from(&conf)
        .endpoint_resolver(ep)
        .build();
    let s3 = Client::from_conf(s3_conf);
    let buckets = s3.list_buckets().send().await;
    println!("got buckets: {:#?}", buckets);
}

You ca…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@brainstorm
Comment options

@brainstorm
Comment options

Answer selected by brainstorm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants