I am a beginner in AWS and I trained on my computer a RandomForestClassifier with scikit-learn and I used joblib to get my model in pkl format.
Now I would like, to reuse this RandomForest in AWS Lambda. Since it needs sklearn.externals to load my model again, I have made a Zip directory which contains Numpy, Scipy, sklearn, my code and my model in pkl format. I put this zip in a S3 bucket to execute my code in Lambda.
I would like to know if then, it is possible to use this model using model.predict() ? I didn't find any documentation about this specific problem.
Actually, I succeed using URLs. I put my model .pkl in a S3 Bucket, and I can get it using urllib2.
Here is my code, if anyone ever encounters the same problem :
req = urllib2.Request(url=url_model)
f = urllib2.urlopen(req)
model = cPickle.load(f)
It only works if the file is public. If you need it to be private, you can generate a presigned URL using boto3 like this :
url_model = s3.generate_presigned_url(
ClientMethod='get_object',
ExpiresIn=1,
Params={
'Bucket': 'my-bucket',
'Key': 'mymodel.pkl'
}
)