From 1f8ffa16ed0b998ad6230fcb46f3ab6595368b67 Mon Sep 17 00:00:00 2001 From: Yuhao Su <31772373+yuhao-su@users.noreply.github.com> Date: Thu, 7 Mar 2024 22:39:12 -0600 Subject: [PATCH] fix(source): don't replace all '/' in s3 path to empty str (#15530) --- src/connector/src/aws_utils.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/connector/src/aws_utils.rs b/src/connector/src/aws_utils.rs index 1578c7b844422..74d9fdd0b0649 100644 --- a/src/connector/src/aws_utils.rs +++ b/src/connector/src/aws_utils.rs @@ -15,7 +15,7 @@ use std::collections::HashMap; use std::time::Duration; -use anyhow::Context; +use anyhow::{anyhow, Context}; use aws_config::timeout::TimeoutConfig; use aws_sdk_s3::{client as s3_client, config as s3_config}; use url::Url; @@ -111,13 +111,16 @@ pub async fn load_file_descriptor_from_s3( let bucket = location .domain() .with_context(|| format!("illegal file path {}", location))?; - let key = location.path().replace('/', ""); + let key = location + .path() + .strip_prefix('/') + .ok_or_else(|| anyhow!("s3 url {location} should have a '/' at the start of path."))?; let sdk_config = config.build_config().await?; let s3_client = s3_client(&sdk_config, Some(default_conn_config())); let response = s3_client .get_object() .bucket(bucket.to_string()) - .key(&key) + .key(key) .send() .await .with_context(|| format!("failed to get file from s3 at `{}`", location))?;