Back
I'm providing the lambda code for saving CSV int S3 change it as per your specification.
import boto3import csvimport ios3 = boto3.client('s3')ec2 = boto3.client('ec2')def lambda_handler(event, context): csvio = io.StringIO() writer = csv.writer(csvio) writer.writerow(['id', 'name']) paginator = ec2.get_paginator('describe_security_groups').paginate() for page in paginator: for item in page['SecurityGroups']: identity = item['GroupId'] name = item['GroupName'] writer.writerow([identity, name]) s3.put_object(Body=csvio.getvalue(), ContentType='text/csv', Bucket='<bucket>', Key='<filename.csv>') csvio.close()
import boto3
import csv
import io
s3 = boto3.client('s3')
ec2 = boto3.client('ec2')
def lambda_handler(event, context):
csvio = io.StringIO()
writer = csv.writer(csvio)
writer.writerow(['id', 'name'])
paginator = ec2.get_paginator('describe_security_groups').paginate()
for page in paginator:
for item in page['SecurityGroups']:
identity = item['GroupId']
name = item['GroupName']
writer.writerow([identity, name])
s3.put_object(Body=csvio.getvalue(), ContentType='text/csv', Bucket='<bucket>', Key='<filename.csv>')
csvio.close()
Want to learn more about AWS, Come & join: AWS Certification
Learn how we helped 50,000+ professionals like you !
31k questions
32.8k answers
501 comments
693 users