Skip to content

Commit

Permalink
Merge pull request #391 from pietroalbini/aws-iam-role
Browse files Browse the repository at this point in the history
allow authenticating to AWS with the EC2 instance role
  • Loading branch information
pietroalbini authored Oct 8, 2019
2 parents 62819fc + 8ee6c6b commit e17ec5c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/db/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use error::Result;
use failure::err_msg;
use rusoto_s3::{S3, PutObjectRequest, GetObjectRequest, S3Client};
use rusoto_core::region::Region;
use rusoto_credential::EnvironmentProvider;
use rusoto_credential::DefaultCredentialsProvider;


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

0 comments on commit e17ec5c

Please sign in to comment.