Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to take AWS credentials from environment variables #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion aws_ir/libs/connection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import boto3
import logging
import os

logger = logging.getLogger(__name__)

Expand All @@ -12,8 +13,25 @@ def __init__(self, type, service=None, region='us-west-2', profile='default'):
self.client = None
self.resource = None
self.profile = profile
self.aws_access_key_id= os.getenv('AWS_ACCESS_KEY_ID', None)
self.aws_secret_access_key= os.getenv('AWS_SECRET_ACCESS_KEY', None)
self.aws_session_token = os.getenv('AWS_SESSION_TOKEN', None)
try:
boto3.setup_default_session(profile_name=self.profile)
session_kwargs = {}
session_kwargs['profile_name'] = self.profile
if self.aws_access_key_id is not None:
session_kwargs["aws_access_key_id"] = self.aws_access_key_id
logger.debug("Took access key id from env")
if self.aws_secret_access_key is not None:
session_kwargs["aws_secret_access_key"] = self.aws_secret_access_key
logger.debug("Took secret access key from env")
if self.aws_session_token is not None:
session_kwargs["aws_session_token"] = self.aws_session_token
logger.debug("Took session token from env")
else:
session_kwargs['profile_name'] = self.profile
logger.debug("No session token in the env, setting profile name instead")
boto3.setup_default_session(**session_kwargs)
except Exception as e:
logger.info("Problem setting default boto3 session: {}".format(e))

Expand Down