Skip to content

Commit

Permalink
Fix Docker env
Browse files Browse the repository at this point in the history
  • Loading branch information
pbdco committed Dec 22, 2024
1 parent f67b547 commit 58e42c9
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions aws_spotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import textwrap
import numpy as np
import json
import os

# Constants
DEFAULT_DAYS = 30
Expand Down Expand Up @@ -85,7 +86,16 @@ def __init__(self, config: SpotPriceConfig):
self.loading = False
self.loading_thread: Optional[threading.Thread] = None
try:
self.session = boto3.Session(profile_name=config.profile)
# First try environment variables
if 'AWS_ACCESS_KEY_ID' in os.environ and 'AWS_SECRET_ACCESS_KEY' in os.environ:
self.session = boto3.Session(
aws_access_key_id=os.environ['AWS_ACCESS_KEY_ID'],
aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
aws_session_token=os.environ.get('AWS_SESSION_TOKEN') # Optional
)
else:
# Fall back to profile if no environment variables
self.session = boto3.Session(profile_name=config.profile)
except botocore.exceptions.ProfileNotFound:
raise AWSError(
f"AWS profile '{config.profile}' not found",
Expand All @@ -94,7 +104,17 @@ def __init__(self, config: SpotPriceConfig):
"1. Check your AWS credentials file (~/.aws/credentials)\n"
"2. Ensure the profile exists and is correctly configured\n"
"3. Available profiles can be found in ~/.aws/credentials\n"
"4. Use --profile <name> to specify a different profile"
"4. Use --profile <n> to specify a different profile"
)
)
except Exception as e:
raise AWSError(
f"Failed to initialize AWS session: {str(e)}",
help_text=(
"\nTo fix this:\n"
"1. Make sure your AWS credentials are valid\n"
"2. Check if your credentials have expired\n"
"3. Ensure you have the necessary permissions"
)
)

Expand Down

0 comments on commit 58e42c9

Please sign in to comment.