How do I pass json file in boto3

故事扮演 提交于 2019-12-11 23:29:40

问题


How do I pass json file as an argument in boto3?

import boto3

client = boto3.client('route53')
doc = open('policy.json', 'rb').read()

response = client.create_traffic_policy(
    Name = 'test2',
    Document = '?????',
    Comment = 'new traffic policy'
)

I want to pass a json file in the place of Document


回答1:


you can use the JSON library

import boto3
import json

client = boto3.client('route53')
doc = json.loads(open('cp.json', 'rb').read())

response = client.create_traffic_policy(
    Name = 'test2',
    Document = json.dumps(doc),
    Comment = 'new traffic policy'
)


来源:https://stackoverflow.com/questions/49375885/how-do-i-pass-json-file-in-boto3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!