在 AWS 中,我尝试使用 Lambda 函数将文件保存到 Python 中的 S3。虽然这可以在我的本地计算机上运行,但我无法让它在 Lambda 中运行。我一整天都在研究这个问题,非常感谢您的帮助。谢谢。
def pdfToTable(PDFfilename, apiKey, fileExt, bucket, key):
# parsing a PDF using an API
fileData = (PDFfilename, open(PDFfilename, "rb"))
files = {"f": fileData}
postUrl = "https://pdftables.com/api?key={0}&format={1}".format(apiKey, fileExt)
response = requests.post(postUrl, files=files)
response.raise_for_status()
# this code is probably the problem!
s3 = boto3.resource('s3')
bucket = s3.Bucket('transportation.manifests.parsed')
with open('/tmp/output2.csv', 'rb') as data:
data.write(response.content)
key = 'csv/' + key
bucket.upload_fileobj(data, key)
Run Code Online (Sandbox Code Playgroud)
# FYI, on my own computer, this saves the file
with open('output.csv', "wb") …Run Code Online (Sandbox Code Playgroud)