-
Notifications
You must be signed in to change notification settings - Fork 2
/
credentials.py
29 lines (22 loc) · 1.01 KB
/
credentials.py
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
import boto3
import platform as platform
import yaml
from os import path
def boto3_start_service(st_aws_service='s3'):
st_plotform = platform.release()
# platform specific path
if 'amzn' not in st_plotform:
snm_aws_yml = "C:/Users/fan/fanwangecon.github.io/_data/aws.yml"
if path.isfile(snm_aws_yml):
fl_yaml = open(snm_aws_yml)
ls_dict_yml = yaml.load(fl_yaml, Loader=yaml.BaseLoader)
# Get the first element of the yml list of dicts
aws_yml_dict_yml = ls_dict_yml[0]
# Use AWS Personal Access Keys etc to start boto3 client
aws_service = boto3.client(st_aws_service,
aws_access_key_id=aws_yml_dict_yml['aws_access_key_id'],
aws_secret_access_key=aws_yml_dict_yml['aws_secret_access_key'],
region_name=aws_yml_dict_yml['region'])
else:
aws_service = boto3.client(st_aws_service)
return aws_service