-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcredentials.py
More file actions
36 lines (25 loc) · 1.03 KB
/
credentials.py
File metadata and controls
36 lines (25 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import config
import ConfigParser
import os
def get_aws_cli_config_file_path(
aws_cli_config_file='config',
home_path=os.path.expanduser('~'),
):
aws_cli_config_file_path = os.path.join(home_path, '.aws', aws_cli_config_file)
return aws_cli_config_file_path
def get_credentials(
environment,
):
# Get AWS account_id from account name
aws_account_id = config.AWS_ACCOUNTS[environment]
# Assemble profile name
profile_name = 'profile {}'.format(environment)
# Get AWS CLI config path
aws_cli_config_file_path = get_aws_cli_config_file_path()
# get AWS credentials from init profiles
configuration = ConfigParser.SafeConfigParser()
configuration.read(aws_cli_config_file_path)
aws_access_key_id = configuration.get(profile_name, 'aws_access_key_id')
aws_secret_access_key = configuration.get(profile_name, 'aws_secret_access_key')
aws_session_token = configuration.get(profile_name, 'aws_session_token')
return aws_access_key_id, aws_secret_access_key, aws_session_token