[英]How to read log file from s3 (cloudtrail) in Lambda function
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)我刚开始使用 aws,不知道如何从 lambda 中读取由 CloudTrail 创建的 s3 中的日志文件(使用 python-boto3)
First you need to assign proper permissions to your IAM role.首先,您需要为您的 IAM 角色分配适当的权限。 For code - Use boto3 library (AWS - SDK) to write lambda function.对于代码 - 使用 boto3 库 (AWS - SDK) 编写 lambda function。
Code for lambda handler: lambda 处理程序的代码:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.