AWS Lambda - S3 put_object Invalid type for parameter Body











up vote
0
down vote

favorite
1












I have a hosted zone in route 53 and would like to have the contents of the hostzone object stored in S3 but I am getting an error. I am thinking Body is the correct parameter but maybe this is because the object is in JSON format?



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()


Here is the error:



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









share|improve this question
























  • Are you sure this is in JSON format and not an object?
    – tkausl
    Nov 11 at 0:56












  • Not 100%, reviewing the docs over here: boto3.amazonaws.com/v1/documentation/api/latest/reference/…
    – juanald_reagan
    Nov 11 at 1:01






  • 1




    Looks like it returns a dict, so you need to json encode it manually before passing it to put_object.
    – tkausl
    Nov 11 at 1:02










  • Thanks it worked, updating to include your recommendation!
    – juanald_reagan
    Nov 11 at 1:19















up vote
0
down vote

favorite
1












I have a hosted zone in route 53 and would like to have the contents of the hostzone object stored in S3 but I am getting an error. I am thinking Body is the correct parameter but maybe this is because the object is in JSON format?



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()


Here is the error:



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









share|improve this question
























  • Are you sure this is in JSON format and not an object?
    – tkausl
    Nov 11 at 0:56












  • Not 100%, reviewing the docs over here: boto3.amazonaws.com/v1/documentation/api/latest/reference/…
    – juanald_reagan
    Nov 11 at 1:01






  • 1




    Looks like it returns a dict, so you need to json encode it manually before passing it to put_object.
    – tkausl
    Nov 11 at 1:02










  • Thanks it worked, updating to include your recommendation!
    – juanald_reagan
    Nov 11 at 1:19













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I have a hosted zone in route 53 and would like to have the contents of the hostzone object stored in S3 but I am getting an error. I am thinking Body is the correct parameter but maybe this is because the object is in JSON format?



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()


Here is the error:



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









share|improve this question















I have a hosted zone in route 53 and would like to have the contents of the hostzone object stored in S3 but I am getting an error. I am thinking Body is the correct parameter but maybe this is because the object is in JSON format?



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()


Here is the error:



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






python amazon-web-services amazon-s3 aws-lambda boto3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 4:53









John Rotenstein

64.7k769113




64.7k769113










asked Nov 11 at 0:50









juanald_reagan

717




717












  • Are you sure this is in JSON format and not an object?
    – tkausl
    Nov 11 at 0:56












  • Not 100%, reviewing the docs over here: boto3.amazonaws.com/v1/documentation/api/latest/reference/…
    – juanald_reagan
    Nov 11 at 1:01






  • 1




    Looks like it returns a dict, so you need to json encode it manually before passing it to put_object.
    – tkausl
    Nov 11 at 1:02










  • Thanks it worked, updating to include your recommendation!
    – juanald_reagan
    Nov 11 at 1:19


















  • Are you sure this is in JSON format and not an object?
    – tkausl
    Nov 11 at 0:56












  • Not 100%, reviewing the docs over here: boto3.amazonaws.com/v1/documentation/api/latest/reference/…
    – juanald_reagan
    Nov 11 at 1:01






  • 1




    Looks like it returns a dict, so you need to json encode it manually before passing it to put_object.
    – tkausl
    Nov 11 at 1:02










  • Thanks it worked, updating to include your recommendation!
    – juanald_reagan
    Nov 11 at 1:19
















Are you sure this is in JSON format and not an object?
– tkausl
Nov 11 at 0:56






Are you sure this is in JSON format and not an object?
– tkausl
Nov 11 at 0:56














Not 100%, reviewing the docs over here: boto3.amazonaws.com/v1/documentation/api/latest/reference/…
– juanald_reagan
Nov 11 at 1:01




Not 100%, reviewing the docs over here: boto3.amazonaws.com/v1/documentation/api/latest/reference/…
– juanald_reagan
Nov 11 at 1:01




1




1




Looks like it returns a dict, so you need to json encode it manually before passing it to put_object.
– tkausl
Nov 11 at 1:02




Looks like it returns a dict, so you need to json encode it manually before passing it to put_object.
– tkausl
Nov 11 at 1:02












Thanks it worked, updating to include your recommendation!
– juanald_reagan
Nov 11 at 1:19




Thanks it worked, updating to include your recommendation!
– juanald_reagan
Nov 11 at 1:19












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










tkausl answered the question in the comments:



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


update:



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()





share|improve this answer























  • Please don't edit the solution into the question. Future visitors looking at the question will assume that the code you are showing will generate the error, and of course it won't, because it's been fixed. Leave the incorrect code in the question, and put the solution in the answer.
    – Michael - sqlbot
    Nov 11 at 1:33






  • 1




    fixed it, thanks!
    – juanald_reagan
    Nov 11 at 1:47











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244866%2faws-lambda-s3-put-object-invalid-type-for-parameter-body%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










tkausl answered the question in the comments:



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


update:



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()





share|improve this answer























  • Please don't edit the solution into the question. Future visitors looking at the question will assume that the code you are showing will generate the error, and of course it won't, because it's been fixed. Leave the incorrect code in the question, and put the solution in the answer.
    – Michael - sqlbot
    Nov 11 at 1:33






  • 1




    fixed it, thanks!
    – juanald_reagan
    Nov 11 at 1:47















up vote
1
down vote



accepted










tkausl answered the question in the comments:



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


update:



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()





share|improve this answer























  • Please don't edit the solution into the question. Future visitors looking at the question will assume that the code you are showing will generate the error, and of course it won't, because it's been fixed. Leave the incorrect code in the question, and put the solution in the answer.
    – Michael - sqlbot
    Nov 11 at 1:33






  • 1




    fixed it, thanks!
    – juanald_reagan
    Nov 11 at 1:47













up vote
1
down vote



accepted







up vote
1
down vote



accepted






tkausl answered the question in the comments:



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


update:



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()





share|improve this answer














tkausl answered the question in the comments:



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


update:



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()






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 1:46

























answered Nov 11 at 1:29









juanald_reagan

717




717












  • Please don't edit the solution into the question. Future visitors looking at the question will assume that the code you are showing will generate the error, and of course it won't, because it's been fixed. Leave the incorrect code in the question, and put the solution in the answer.
    – Michael - sqlbot
    Nov 11 at 1:33






  • 1




    fixed it, thanks!
    – juanald_reagan
    Nov 11 at 1:47


















  • Please don't edit the solution into the question. Future visitors looking at the question will assume that the code you are showing will generate the error, and of course it won't, because it's been fixed. Leave the incorrect code in the question, and put the solution in the answer.
    – Michael - sqlbot
    Nov 11 at 1:33






  • 1




    fixed it, thanks!
    – juanald_reagan
    Nov 11 at 1:47
















Please don't edit the solution into the question. Future visitors looking at the question will assume that the code you are showing will generate the error, and of course it won't, because it's been fixed. Leave the incorrect code in the question, and put the solution in the answer.
– Michael - sqlbot
Nov 11 at 1:33




Please don't edit the solution into the question. Future visitors looking at the question will assume that the code you are showing will generate the error, and of course it won't, because it's been fixed. Leave the incorrect code in the question, and put the solution in the answer.
– Michael - sqlbot
Nov 11 at 1:33




1




1




fixed it, thanks!
– juanald_reagan
Nov 11 at 1:47




fixed it, thanks!
– juanald_reagan
Nov 11 at 1:47


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244866%2faws-lambda-s3-put-object-invalid-type-for-parameter-body%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python