【问题标题】:Getting error "errorMessage": "[Errno 30] Read-only file system: 'output.txt'" when im appending logs to the file将日志附加到文件时出现错误“errorMessage”:“[Errno 30] 只读文件系统:'output.txt'”
【发布时间】:2020-07-22 00:54:34
【问题描述】:

当我尝试将过滤后的数据附加到 output.txt 时出现错误

错误:响应:

{
  "errorMessage": "[Errno 30] Read-only file system: 'output.txt'",
  "errorType": "OSError",
  "stackTrace": [
    [
      "/var/task/lambda_function.py",
      37,
      "lambda_handler",
      "open_file = open(\"output.txt\", \"a\")"
    ]
  ]
}
import json
import urllib.parse
import boto3

print('Loading function')


s3 = boto3.client('s3')

def lambda_handler(event, context):


    #1 - Get the bucket name
    bucket = event['Records'][0]['s3']['bucket']['name']

    #2 - Get the file/key name
    key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8')



    #3 - Fetch the file from S3
    response = s3.get_object(Bucket=bucket, Key=key)
    target_bucket='blocketrequest'
    FILE='Filtered' + key



    #4 - Deserialize the file's content
    text = response["Body"].read().decode()
    e  = text.split("\n")


    #5 - Print the content
    print(text)

    #6 - Parse and print the Action
    open_file = open("output.txt", "a")

    for each in e:
        loaded_data = json.loads(e)
        if loaded_data["action"] == "ALLOW":
            print("dropped")
        else :
            open_file.write(json.dumps(loaded_data))
    open_file.close()        
          s3.put_object(Body=Output,Bucket='target_bucket',Key='FILE')
    print('File written to s3')

【问题讨论】:

    标签: python amazon-s3 web-application-firewall amazon-waf


    【解决方案1】:

    通过在正文中添加 json.dumps 解决

    【讨论】:

    • 您能否展示一下您的新工作代码是什么样的?谢谢。
    猜你喜欢
    • 2018-01-18
    • 2022-11-23
    • 2020-07-01
    • 2020-05-19
    • 2018-10-05
    • 2013-06-19
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多