0

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)

  • 1
    This 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 Answers2

1

You just need to assign a role to the lambda function that has IAM permissions to read the object in S3. A detailed walkthrough can be found from AWS here.

Foghorn
  • 2,238
  • 2
  • 13
  • 35
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
S.B
  • 13,077
  • 10
  • 22
  • 49
D kashyap
  • 25
  • 7