[英]How to save a Python Dictionary as a Pickle object on AWS S3
I have a python dictionary. 我有一个python字典。 I want to save it as a pickle object in AWS S3.
我想将其另存为AWS S3中的泡菜对象。
I am trying this - 我正在尝试-
import boto3
import pickle
#Connect to S3 default profile
s3 = boto3.client('s3')
serializedMyData = pickle.dumps(myDictionary)
s3.put_object(Bucket='mytestbucket',Key='myDictionary')
The script runs successfully and I get a file with name * myDictionary* in the S3. 该脚本成功运行,并且在S3中得到一个名为* myDictionary *的文件。 But it is not a pickle and it has 0 bytes.
但这不是泡菜,它有0个字节。
I edited my code a little bit - 我编辑了一点代码-
import boto3
import pickle
#Connect to S3 default profile
s3 = boto3.client('s3')
serializedMyData = pickle.dumps(myDictionary)
s3.put_object(Bucket='mytestbucket',Key='myDictionary').put(Body=serializedMyData)
But then I get this error - 但是然后我得到这个错误-
AttributeError: 'dict' object has no attribute 'put'
What should I do ? 我该怎么办 ?
Try s3.put_object(Bucket='mytestbucket',Key='myDictionary', Body=serializedMyData)
尝试
s3.put_object(Bucket='mytestbucket',Key='myDictionary', Body=serializedMyData)
see https://docs.aws.amazon.com/code-samples/latest/catalog/python-s3-put_object.py.html 参见https://docs.aws.amazon.com/code-samples/latest/catalog/python-s3-put_object.py.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.