def lambda_handler()

in python3.12/efs/{{cookiecutter.project_name}}/hello_efs/app.py [0:0]


def lambda_handler(event, context):
    wrote_file = False
    contents = None
    # The files in EFS are not only persistent across executions, but if multiple
    # Lambda functions are mounted to the same EFS file system, you can read and
    # write files from either function.
    if not FILE.is_file():
        with open(FILE, 'w') as f:
            contents = "Hello, EFS!\n"
            f.write(contents)
            wrote_file = True
    else:
        with open(FILE, 'r') as f:
            contents = f.read()
    return {
        "statusCode": 200,
        "body": json.dumps({
            "file_contents": contents,
            "created_file": wrote_file
        }),
    }