in source/extract-tag-data-lambda.py [0:0]
def lambda_handler(event, context):
logger.info(sanitize_json(event))
if os.environ[("CustomerKeys")].strip() !='':
try:
file_Header=['Date','DateTime','AccountId','AccountName','AccountEmail',
'RegionName','ResourceType','ResourceArn','ResourceId']
customerKeys=[tag.strip() for tag in os.environ[("CustomerKeys")].strip().split(",")]
logger.info("Tags: "+str(customerKeys))
file_Header.extend(customerKeys)
tagInfo=getTagInfo(str(event['AccountId']),event['Region'],event['ResourceType'],customerKeys,event['Date'],event['DateTime'],event['AccountName'],event['AccountEmail'])
if len(tagInfo.keys()) > 0:
#Resource File Name
resourceFilename=(str(event['ResourceType'])+"_"+str(event['AccountId'])+"_"+event['Region']+"_"+str(event['Date'])+"_"+str(datetime.utcnow().strftime("%H-%M-%S"))+'.csv')
#Write the Values into a csv file
write2csv(tagInfo,resourceFilename,file_Header)
#Construct S3 Path
resourceFilePath='Tags/'+str(event['ResourceType'])+'/'+str(date.today().year)+'/'+str(date.today().month)+'/'+str(date.today().day)+'/'
#Copy file to S3
writeToS3(resourceFilename,resourceFilePath)
logger.info("Clean /tmp/")
call('rm -rf /tmp/*', shell=True)
except ClientError as e:
e = sanitize_string(e)
logger.error("Unexpected client error %s" % e)
raise AWSTrustedAdvisorExplorerGenericException(e)
except Exception as f:
f = sanitize_string(f)
logger.error("Unexpected exception: %s" % f)
raise AWSTrustedAdvisorExplorerGenericException(f)