Ad

How To Save A Python Dictionary As A Pickle Object On AWS S3

I have a python dictionary. I want to save it as a pickle object in 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. But it is not a pickle and it has 0 bytes.

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 ?

Ad

Answer

Try 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

Ad
source: stackoverflow.com
Ad