I have just started using aws and have no idea on how to read log files in lambda from s3 that have been created by CloudTrail (using python-boto3)
Asked
Active
Viewed 443 times
0
-
1This might assist you: [Tutorial: Triggering a Lambda function with AWS CloudTrail events - AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/with-cloudtrail-example.html) – John Rotenstein Jul 10 '21 at 00:32
2 Answers
0
First you need to assign proper permissions to your IAM role. For code - Use boto3 library (AWS - SDK) to write lambda function.
Code for lambda handler:
def lambda_handler(event, context):
# Goal 1: Read file from csv
object_key = "event_history_j.json" # Name of file
bucket = "demo-cloudtrail-logs-ec2" # Name of bucket
client = boto3.client("s3")
data = client.get_object(Bucket=bucket, Key=object_key)["Body"].read()
return data