Skip to content

Commit e17ec5c

Browse files
authored
Merge pull request #391 from pietroalbini/aws-iam-role
allow authenticating to AWS with the EC2 instance role
2 parents 62819fc + 8ee6c6b commit e17ec5c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/db/file.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use error::Result;
1414
use failure::err_msg;
1515
use rusoto_s3::{S3, PutObjectRequest, GetObjectRequest, S3Client};
1616
use rusoto_core::region::Region;
17-
use rusoto_credential::EnvironmentProvider;
17+
use rusoto_credential::DefaultCredentialsProvider;
1818

1919

2020
fn get_file_list_from_dir<P: AsRef<Path>>(path: P,
@@ -115,12 +115,19 @@ pub fn get_path(conn: &Connection, path: &str) -> Option<Blob> {
115115
fn s3_client() -> Option<S3Client> {
116116
// If AWS keys aren't configured, then presume we should use the DB exclusively
117117
// for file storage.
118-
if std::env::var_os("AWS_ACCESS_KEY_ID").is_none() {
118+
if std::env::var_os("AWS_ACCESS_KEY_ID").is_none() && std::env::var_os("FORCE_S3").is_none() {
119119
return None;
120120
}
121+
let creds = match DefaultCredentialsProvider::new() {
122+
Ok(creds) => creds,
123+
Err(err) => {
124+
warn!("failed to retrieve AWS credentials: {}", err);
125+
return None;
126+
}
127+
};
121128
Some(S3Client::new_with(
122129
rusoto_core::request::HttpClient::new().unwrap(),
123-
EnvironmentProvider::default(),
130+
creds,
124131
std::env::var("S3_ENDPOINT").ok().map(|e| Region::Custom {
125132
name: "us-west-1".to_owned(),
126133
endpoint: e,

0 commit comments

Comments
 (0)