in smart-mirror-full/extracted/device/script/parameter_store_helper.py [0:0]
def fetch_and_store_parameters():
try:
print('getting parameters')
hostname=os.uname()[1]
region=os.getenv('AWS_REGION', 'eu-west-1')
print('The region we are using is ' + region)
#read parameters from parameter store
ssm = boto3.client('ssm',region_name=region)
parameterPath=f'/smart-mirror/device/{hostname}'
response = ssm.get_parameters_by_path(Path=parameterPath, Recursive=True, WithDecryption=False)
# transform and dump yaml file to /home/smart-mirror/conf.yml
parameters = []
for parameter in response['Parameters']:
parameters.append({'Name': parameter['Name'].replace(parameterPath,''), 'Value': parameter['Value']})
config=yaml.dump({'Description': 'Smart Mirror Parameters', 'Parameters': parameters})
Path("/home/smart-mirror").mkdir(parents=True, exist_ok=True)
text_file = open('/home/smart-mirror/conf.yml', 'wt')
text_file.write(config)
text_file.close()
except Exception as e:
logger.info(f'Error in while fetching parameters - Using old parameters if possible: {e}')
logger.error(f'Stack: {traceback.format_exc()}')