AWS Lambda - S3 put_object Invalid type for parameter Body
up vote
0
down vote
favorite
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
add a comment |
up vote
0
down vote
favorite
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
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
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
python amazon-web-services amazon-s3 aws-lambda boto3
edited Nov 11 at 4:53
John Rotenstein
65.3k771115
65.3k771115
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
add a comment |
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
add a comment |
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()
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
add a comment |
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()
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
add a comment |
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()
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
add a comment |
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()
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()
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
add a comment |
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
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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