Skip to content

Commit a150a4b

Browse files
fix: improve ability to control dynamo creds cache (#1870)
Exposes `AwsCredentialAdapter` for purpose of allowing its cache to be used by the dynamo client. This is necessary to get around a timeout loading credentials ... Currently dynamo client default to lazy_builder https://docs.rs/aws-sdk-dynamodb/0.34.0/src/aws_sdk_dynamodb/config.rs.html#790 This lazy cache has a 5 second timeout loading credentials: https://github.com/smithy-lang/smithy-rs/blob/e78c60dbf169403eedceb1b718b862b0c5e5ee09/aws/rust-runtime/aws-credential-types/src/cache/lazy_caching.rs#L93 This change allows the caller to more easily pass their own `ProvideCredentials` implementation and rely on the caching built into `AwsCredentialAdapter`. ```rs use aws_config::default_provider::credentials::DefaultCredentialsChain; use aws_credential_types::provider::SharedCredentialsProvider; use lance::dataset::ReadParams; use lance_io::object_store::{AwsCredentialAdapter, ObjectStoreParams}; use vectordb::Database; let creds_provider = Arc::new(AwsCredentialAdapter::new( Arc::new(SharedCredentialsProvider::new(DefaultCredentialsChain::builder().build().await)), ObjectStoreParams::default().s3_credentials_refresh_offset, )); let db = Database::connect("s3://my-bucket/my-db?engine=ddb&ddbTableName=my-dyn-table").await.unwrap(); let table = db.open_table_with_params("my-table", ReadParams { store_options: Some(ObjectStoreParams { aws_credentials: Some(creds_provider), ..Default::default() }), ..ReadParams::default() }).await.unwrap(); ```
1 parent 710c5ad commit a150a4b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

rust/lance-io/src/object_store.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const AWS_CREDS_CACHE_KEY: &str = "aws_credentials";
108108

109109
/// Adapt an AWS SDK cred into object_store credentials
110110
#[derive(Debug)]
111-
struct AwsCredentialAdapter {
111+
pub struct AwsCredentialAdapter {
112112
pub inner: Arc<dyn ProvideCredentials>,
113113

114114
// RefCell can't be shared accross threads, so we use HashMap
@@ -119,7 +119,10 @@ struct AwsCredentialAdapter {
119119
}
120120

121121
impl AwsCredentialAdapter {
122-
fn new(provider: Arc<dyn ProvideCredentials>, credentials_refresh_offset: Duration) -> Self {
122+
pub fn new(
123+
provider: Arc<dyn ProvideCredentials>,
124+
credentials_refresh_offset: Duration,
125+
) -> Self {
123126
Self {
124127
inner: provider,
125128
cache: Arc::new(RwLock::new(HashMap::new())),

rust/lance-table/src/io/commit.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ use lance_io::object_store::ObjectStoreParams;
6161
#[cfg(feature = "dynamodb")]
6262
use {
6363
self::external_manifest::{ExternalManifestCommitHandler, ExternalManifestStore},
64+
aws_credential_types::cache::CredentialsCache,
6465
lance_io::object_store::{build_aws_credential, StorageOptions},
6566
object_store::aws::AmazonS3ConfigKey,
6667
std::borrow::Cow,
@@ -295,7 +296,10 @@ async fn build_dynamodb_external_store(
295296

296297
let dynamodb_config = aws_sdk_dynamodb::config::Builder::new()
297298
.region(Some(Region::new(region.to_string())))
298-
.credentials_provider(OSObjectStoreToAwsCredAdaptor(creds));
299+
.credentials_provider(OSObjectStoreToAwsCredAdaptor(creds))
300+
// caching should be handled by passed AwsCredentialProvider
301+
.credentials_cache(CredentialsCache::no_caching());
302+
299303
let dynamodb_config = match env::var("DYNAMODB_ENDPOINT") {
300304
Ok(endpoint) => dynamodb_config.endpoint_url(endpoint),
301305
_ => dynamodb_config,

0 commit comments

Comments
 (0)