繁体   English   中英

aws lambda python append 从 S3 ZA8CFDE6331BD59EB2AC96F8911C4B6666 归档

[英]aws lambda python append to file from S3 object

我正在尝试将从 S3 object 读取的内容写入文件。 我在做同样的事情时遇到语法错误。

    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)

错误:“errorMessage”:“write() 参数必须是 str,而不是字节”

以二进制模式打开文件应该可以解决问题:

with open(filename, 'ab') as file:
    file.write(jenkinsfile)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM