使用boto3将XML文件上传到S3存储桶
我正在尝试将XML文件上传到带有Lambda功能和HTTP请求的AWS的S3存储桶中。主要问题是我无法转换由HTTP请求的正文传递的XML文件。
import json
import boto3
s3 = boto3.client('s3')
def lambda_handler(event, context):
bucket = 'xmlresultmarco'
fileName = 'Test'+'.xml'
uploadByteStream = event
try:
s3.put_object(Bucket = bucket, Key = fileName, Body = uploadByteStream )
return "Upload completed"
except Exception as e:
return e
raise e
有人可以帮助我吗?
I am trying to upload an XML file to a s3 bucket with AWS with a lambda function and a HTTP request. The principal problem is that I am not able to convert the XML file passed by the body of the HTTP request.
import json
import boto3
s3 = boto3.client('s3')
def lambda_handler(event, context):
bucket = 'xmlresultmarco'
fileName = 'Test'+'.xml'
uploadByteStream = event
try:
s3.put_object(Bucket = bucket, Key = fileName, Body = uploadByteStream )
return "Upload completed"
except Exception as e:
return e
raise e
Is there someone that can help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一些可以让您入门的代码。
lambda函数定义可能看起来像这样。
然后下载功能可能看起来像这样。我使用多部分来满足大型文件。
显然,根据Mark的观点,我在这里没有处理任何XML转换。阅读文件时,您需要弄清楚这一点。
Here is some code to get you started.
The lambda function definition might look something like this.
Then the download function might look like this. I use multi-part to cater for large files.
Clearly I am not dealing with any XML conversion here, per Mark's point. You will need to figure that out when you read the file.