Получение ошибки «errorMessage»: «[Errno 30] Файловая система только для чтения:« output.txt »» при добавлении журналов в файл - PullRequest
0 голосов
/ 09 апреля 2020

Я получаю сообщение об ошибке при попытке добавить отфильтрованные данные в файл output.txt

error: Response:

{
  "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')

1 Ответ

0 голосов
/ 13 апреля 2020

решается добавлением json .dumps в тело

...