【发布时间】:2021-05-01 16:01:19
【问题描述】:
我目前正在尝试将我在 AWS lambda 函数中生成的词云保存到我的 s3 存储桶中,我的代码执行gut给出“errorMessage”:“参数验证失败:\n参数正文的类型无效,值:
作为一个错误,我上网查了一下似乎找不到原因,我是否需要将绘图转换为字节才能像这样将其存储在 S3 中?
from wordcloud import WordCloud, STOPWORDS
import matplotlib.pyplot as plt
import boto3
text = "cat cat cat dog dog dog test test hello one two three four five"
generate_word_cloud(text)
def generate_word_cloud(text):
wordcloud = WordCloud(width = 3000,
height = 2000,
random_state=1,
background_color='salmon',
colormap='Pastel1',
collocations=False,
stopwords = STOPWORDS).generate(text)
save_to_bucket(wordcloud)
def save_to_bucket(wordcloud):
#Save tweet list to an s3 bucket
BUCKET_NAME = "1706224-tweets"
FILE_NAME = "wordcloud.png"
s3 = boto3.resource('s3')
object = s3.Object(BUCKET_NAME, FILE_NAME)
object.put(Body=wordcloud)
【问题讨论】:
-
我得到 s3.ServiceResource' 对象没有属性 'upload_fileobj'",这是 python-2 特定的函数吗?
标签: python amazon-web-services matplotlib amazon-s3 aws-lambda