IAM建立Role “Has prohibited field”问题
使用
iam.createRole(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
建立IAM角色时,使用的AssumeRolePolicyDocument json如下:
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::example_bucket"
}
}
结果出现错误提示:
A client error (MalformedPolicyDocument) occurred when calling the CreateRole operation: Has prohibited field Resource
此问题主要原因在于AssumeRolePolicyDocument对应的是IAM设置面板中的信任关系文件,应该放的内容是像如下这样的:
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Principal": {"Service": "ec2.amazonaws.com"},
"Action": "sts:AssumeRole"
}
}
真正需要确定一个role的策略是在AttachRolePolicy函数实现。
参考:# AWS create role - Has prohibited field
网友评论