diff --git a/core/src/services/s3/backend.rs b/core/src/services/s3/backend.rs index 1bcd4a4bfd08..5e8fd0a5436e 100644 --- a/core/src/services/s3/backend.rs +++ b/core/src/services/s3/backend.rs @@ -124,6 +124,8 @@ pub struct S3Config { pub role_arn: Option, /// external_id for this backend. pub external_id: Option, + /// role_session_name for this backend. + pub role_session_name: Option, /// Disable config load so that opendal will not load config from /// environment. /// @@ -358,6 +360,15 @@ impl S3Builder { self } + /// Set role_session_name for this backend. + pub fn role_session_name(mut self, v: &str) -> Self { + if !v.is_empty() { + self.config.role_session_name = Some(v.to_string()) + } + + self + } + /// Set default storage_class for this backend. /// /// Available values: @@ -948,13 +959,19 @@ impl Builder for S3Builder { let default_loader = AwsDefaultLoader::new(client.client(), cfg.clone()); // Build the config for assume role. - let assume_role_cfg = AwsConfig { + let mut assume_role_cfg = AwsConfig { region: Some(region.clone()), role_arn: Some(role_arn), external_id: self.config.external_id.clone(), sts_regional_endpoints: "regional".to_string(), ..Default::default() }; + + // override default role_session_name if set + if let Some(name) = self.config.role_session_name { + assume_role_cfg.role_session_name = name; + } + let assume_role_loader = AwsAssumeRoleLoader::new( client.client(), assume_role_cfg,