I am getting the below error when loading an pickled functiond
我在加载腌制函数时收到以下错误
{
"errorMessage": "Can't get attribute 'customer_transform' on <module '__main__' from '/var/runtime/bootstrap.py'>",
"errorType": "AttributeError",
"stackTrace": [
" File \"/var/task/on_demand_dataset_load_and_transform/handler.py\", line 14, in lambda_handler\n return transform_data(load_response, udf_s3_key)\n",
" File \"/var/task/on_demand_dataset_load_and_transform/transform_data.py\", line 26, in transform_data\n udf = pickle.loads(udf_bytes)\n"
]
}
I am using jupyter notebook to write a function, pickle it and store it in S3.
我正在使用jupyter笔记本编写一个函数,将其pickle并存储在S3中。
def customer_transform(input):
# implementation
import pickle
def serialize_func(func):
return pickle.dumps(func)
serialized_transform = serialize_func(customer_transform)
s3_client.put_object(Body=serialized_transform, Bucket="Bucket_name", Key="key")
When I try to read data from S3 and unpickle it, I am getting the above error. Below is the code
当我试图从S3中读取数据并将其取消拾取时,我会收到上面的错误。下面是代码
udf_bytes = s3_client.get_object(Bucket="Bucket_name", Key="key")["Body"].read()
downloaded_func = pickle.loads(udf_bytes)
更多回答
优秀答案推荐
I resolved this importing dill
我解决了这个进口难题
import dill as pickle
Here is the documentation for dill
这是dill的文档
更多回答
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
您的回答可以通过其他支持信息得到改进。请编辑以添加更多详细信息,如引文或文档,以便其他人可以确认您的答案是正确的。你可以在帮助中心找到更多关于如何写出好答案的信息。
我是一名优秀的程序员,十分优秀!