[英]aws lambda python append to file from S3 object
I am trying to write the contents read from S3 object to a file.我正在尝试将从 S3 object 读取的内容写入文件。 I am getting syntax error while doing the same.
我在做同样的事情时遇到语法错误。
object =s3.get_object(Bucket=bucket_name, Key="toollib/{0}/{1}/stages/{0}.groovy".format(tool,platform))
print(object)
jenkinsfile = object['Body'].read()
print(jenkinsfile)
basepath = '/mnt/efs/{0}/{1}/{2}/'.format(orderid, platform, technology)
filename = basepath+fileName
print(filename)
#file1=open(filename, "a")
with open(filename, 'a') as file:
file.write(jenkinsfile)
Error: "errorMessage": "write() argument must be str, not bytes"错误:“errorMessage”:“write() 参数必须是 str,而不是字节”
Opening the file in binary mode should do the trick:以二进制模式打开文件应该可以解决问题:
with open(filename, 'ab') as file:
file.write(jenkinsfile)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.