gpt4 book ai didi

python - AWS Lambda - S3 put_object 参数主体的类型无效

转载 作者:行者123 更新时间:2023-12-01 01:27:04 25 4
gpt4 key购买 nike

我在路由 53 中有一个托管区域,并且希望将 hostzone 对象的内容存储在 S3 中,但我收到错误。我认为 Body 是正确的参数,但也许这是因为该对象是 JSON 格式?

import boto3
import json

def allwork():
client = boto3.client('route53')
hostzone = client.list_hosted_zones()
bucket_name = "testlambda"
file_name = "r53data.txt"
lambda_path = "/tmp/" + file_name
s3_path = "10102018/" + file_name

s3 = boto3.resource("s3")
s3.Bucket(bucket_name).put_object(Key=s3_path, Body=hostzone)

allwork()

这是错误:

module initialization error: Parameter validation failed:
Invalid type for parameter Body, value: {u'HostedZones':
[{u'ResourceRecordSetCount': 7, u'CallerReference': '814E3.........

最佳答案

tkausl 在评论中回答了问题:

Looks like it returns a dict, so you need to json encode it manually before passing it to put_object 

更新:

import boto3
import json

def allwork():
client = boto3.client('route53')
hostzone = client.list_hosted_zones()
bucket_name = "testlambda"
file_name = "r53data.txt"
lambda_path = "/tmp/" + file_name
s3_path = "10102018/" + file_name

hostzone2=json.dumps(hostzone, ensure_ascii=False)

s3 = boto3.resource("s3")
s3.Bucket(bucket_name).put_object(Key=s3_path, Body=hostzone2)

allwork()

关于python - AWS Lambda - S3 put_object 参数主体的类型无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53244866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com