Skip to content

Commit 2a95b86

Browse files
warp3rtimvaillancourt
authored andcommitted
pull request for issue #259 (#260)
* fixes for S3 IAM role authentication * fixes for S3 IAM role authentication
1 parent 4263d55 commit 2a95b86

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

mongodb_consistent_backup/Upload/S3/S3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def __init__(self, manager, config, timer, base_dir, backup_dir, **kwargs):
2727

2828
self._pool = None
2929

30-
if None in (self.access_key, self.secret_key, self.region):
31-
raise OperationError("Invalid or missing AWS S3 access key, secret key or region detected!")
30+
if self.region is None:
31+
raise OperationError("Invalid or missing AWS S3 region detected!")
3232

3333
self._pool = S3UploadPool(
3434
self.bucket_name,

mongodb_consistent_backup/Upload/S3/S3Session.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,24 @@ def is_forbidden_error(self, e):
4646
def connect(self):
4747
if not self._conn:
4848
try:
49-
logging.debug("Connecting to AWS S3 with Access Key: %s" % self.access_key)
50-
self._conn = boto.s3.connect_to_region(
51-
self.region,
52-
aws_access_key_id=self.access_key,
53-
aws_secret_access_key=self.secret_key,
54-
is_secure=self.secure,
55-
calling_format=self.calling_format
56-
)
57-
logging.debug("Successfully connected to AWS S3 with Access Key: %s" % self.access_key)
49+
if (self.access_key is not None and self.secret_key is not None):
50+
logging.debug("Connecting to AWS S3 with Access Key: %s" % self.access_key)
51+
self._conn = boto.s3.connect_to_region(
52+
self.region,
53+
aws_access_key_id=self.access_key,
54+
aws_secret_access_key=self.secret_key,
55+
is_secure=self.secure,
56+
calling_format=self.calling_format
57+
)
58+
logging.debug("Successfully connected to AWS S3 with Access Key: %s" % self.access_key)
59+
else:
60+
logging.debug("Connecting to AWS S3 with IAM Role")
61+
self._conn = boto.s3.connect_to_region(
62+
self.region,
63+
is_secure=self.secure,
64+
calling_format=self.calling_format
65+
)
66+
logging.debug("Successfully connected to AWS S3 with IAM Role")
5867
except boto.exception.S3ResponseError, e:
5968
if self.is_forbidden_error(e):
6069
logging.error("Not authorized to connect to AWS S3 with Access Key: %s!" % self.access_key)

0 commit comments

Comments
 (0)