我用boto创建一个iam用户,但我有一个错误,无效的json格式。
但似乎我有正确的json变量,你看到问题出在哪里了吗?
你也知道在create_access_key(用户名)之后你知道如何返回秘密访问密钥进行打印吗?
pName = "name"
username = "user"
pJson= {
"Statement": [
{
"Effect": "Allow",
"Action": "*",
"Resource": "*"
}
]
}
import boto.iam.connection
c = boto.iam.connect_to_region("us-east-1")
c.create_user(username)
c.put_user_policy(username, pName, pJson)
c.create_access_key(username)
k = c.get_all_access_keys(username)
print k['list_access_keys_response']['list_access_keys_result']['access_key_metadata'][0]['access_key_id']
# how to return secret access key?
答案 0 :(得分:1)
根据boto documentation,政策文件应该是一个字符串;因此,您自己使用json.dumps
将字典转换为字符串:
policy_document = json.dumps(pJson)
c.put_user_policy(usename, pName, policy_document)