简体   繁体   English

如何从 Lambda 中的 s3 (cloudtrail) 读取日志文件 function

[英]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)

You just need to assign a role to the lambda function that has IAM permissions to read the object in S3.您只需要为 lambda 函数分配一个角色,该函数具有读取 S3 中对象的 IAM 权限。 A detailed walkthrough can be found from AWS here .可以从AWS 此处找到详细的演练。

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.

相关问题 如何在 Lambda 函数中读取 S3 文件(在 python 中) - How to read S3 file in Lambda function(in python) 设置为从 CloudTrail 触发的 CloudWatch 规则不会触发 Lambda function 除非我创建了一个跟踪来将 CloudTrail 日志存储在 S3 存储桶中 - CloudWatch Rule set to trigger from CloudTrail doesn't trigger Lambda function unless I create a Trail to store CloudTrail logs in an S3 bucket 如何使用 lambda 函数和 boto3 从 s3 存储桶中读取 csv 文件? - How to read a csv file from s3 bucket using lambda function and boto3? 如何从Lambda函数解析AWS S3文件 - How to parse an AWS S3 file from a Lambda function 如何从Lambda函数访问S3存储桶中的文件 - How to access file in S3 bucket from lambda function 在AWS中如何使用lambda函数将文件从一个s3存储桶复制到另一个s3存储桶 - In AWS how to Copy file from one s3 bucket to another s3 bucket using lambda function 是否有 lambda 函数可以根据 s3 中的文件上传读取 Athena 查询 - is there a lambda function to read Athena query as per file upload in s3 API 网关 - 从 S3 读取文件,该文件刚刚由 lambda function 在同一 Z65E8800B5C6806AAD8 端点上创建 - API Gateway - Read file from S3 which just created by a lambda function on the same rest endpoint AWS Lambda函数从S3读取并写入Elastic Cache - AWS Lambda function to read from S3 and write to Elastic Cache 如何使用 Node.js AWS Lambda ZC1C425268E68385D1AB5074C17A94 从 S3 读取 CSV 数据 - How to read CSV data from S3 using Node.js AWS Lambda function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM