Skip to content

Commit

Permalink
Fix: Handle missing AWS credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanbouz committed Dec 1, 2018
1 parent 46ec52a commit bbaf110
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 10 additions & 3 deletions samcli/commands/local/lib/local_api_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,20 @@ def _create_xray_service(self):
container_manager = self.lambda_runner.local_runtime.get_container_manager()
xray_daemon_service = LocalXrayDaemonService(container_manager)

aws_creds = self.lambda_runner.get_aws_creds()
region = None or self.lambda_runner.aws_region
key = None
secret = None
aws_creds = self.lambda_runner.get_aws_creds()

if 'region' in aws_creds: # Prefer aws creds region
region = aws_creds['region']

xray_daemon_service.create(key=aws_creds['key'],
secret=aws_creds['secret'],
if 'key' in aws_creds and 'secret' in aws_creds:
key = aws_creds['key']
secret = aws_creds['secret']

xray_daemon_service.create(key=key,
secret=secret,
region=region)

return xray_daemon_service
6 changes: 4 additions & 2 deletions samcli/local/xray/local_xray_daemon_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create(self, key, secret, region):
:param string secret: AWS secret access key.
:param string region: AWS region where X-Ray segments will be emitted to.
:raises UserException: If AWS region is missing.
:raises UserException: If the AWS region or AWS credentials are missing.
"""
xray_daemon_envs = {
'AWS_ACCESS_KEY_ID': key,
Expand All @@ -39,7 +39,9 @@ def create(self, key, secret, region):
}

if not region:
raise UserException("X-Ray requires an AWS region to be specified using --region or an AWS profile.")
raise UserException("X-Ray option requires an AWS region. Please configure your credentials with a region or specify a region using --region.")
if not key and not secret:
raise UserException("X-Ray option requires AWS credentials. Please configure your credentials.")

self._xray_container = XrayContainer(env_vars=xray_daemon_envs)

Expand Down

0 comments on commit bbaf110

Please sign in to comment.