I have something in python 2.7 that works well when writing to CSV, how can I add an output to json in a separate file in the same s3 bucket?
#boto3 library ec2 API describe addresses page
#http://boto3.readthedocs.org/en/latest/reference/services/ec2.html#EC2.Client.describe_addresses
addresses = ec2con.describe_addresses().get('Addresses',[] )
addresseslist = len(addresses)
if addresseslist > 0:
csv_file.write("%s,%s,%s,%s,%s\n"%('','','','',''))
csv_file.write("%s,%s\n"%('EIPS INSTANCE',regname))
csv_file.write("%s,%s,%s,%s\n"%('PublicIp','AllocationId','Domain','InstanceId'))
csv_file.flush()
for address in addresses:
PublicIp=address['PublicIp']
try:
AllocationId=address['AllocationId']
except:
AllocationId="empty"
Domain=address['Domain']
if 'InstanceId' in address:
instanceId=address['InstanceId']
else:
instanceId='empty'
csv_file.write("%s,%s,%s,%s\n"%(PublicIp,AllocationId,Domain,instanceId))
csv_file.flush()...
date_fmt = strftime("%Y_%m_%d", gmtime())
#Give your file path
filepath ='/tmp/AWS_Resources_' + date_fmt + '.csv'
#Save Inventory
s3.Object('s3BUCKETNAME', filename).put(Body=open(filepath, 'rb'))