通过 cloudformation 创建 IAM 角色时 policyName 出错

Jav*_*een 3 json roles aws-cloudformation amazon-iam

这是角色片段:

"InstanceRole": {
  "Type": "AWS::IAM::Role",
  "Properties": {
    "AssumeRolePolicyDocument": {
      "Version" : "2012-10-17",
      "Statement": [ {
        "Effect": "Allow",
        "Principal": {
           "Service" : [ { "Fn::FindInMap": [ "Region2Principal", { "Ref": "AWS::Region" },"EC2Principal" ] } ] },
        "Action"  : [ "sts:AssumeRole" ]
      }]
    },
    "Path": "/",
    "Policies": [{
      "PolicyName": {"Fn::Join" : ["",["AWS::StackName","InstanceApi"] ] },
      "PolicyDocument": {
        "Statement": [{
          "Effect": "Allow",
          "Action": "*",
          "Resource": "*"
        }]
      }
    }]
  }
},
Run Code Online (Sandbox Code Playgroud)

这是错误: The specified value for policyName is invalid. It must contain only alphanumeric characters and/or the following: +=,.@_-

的价值AWS::StackName我输入的tmplt-stack,并且给出了错误产生的策略名称是:tmplt-stack-InstanceApi-O7KF5OL0TA2Q

我不明白为什么 cloudformation 拒绝这个名称,即使它只包含几个“-”字符,并且根据错误消息允许它,其余都是字母数字字符。

Jav*_*een 5

这是我在使用伪参数 AWS::StackNAme 时犯的一个巨大错误,我没有用“Ref”来调用它

"InstanceRole": {
  "Type": "AWS::IAM::Role",
  "Properties": {
    "AssumeRolePolicyDocument": {
      "Version" : "2012-10-17",
      "Statement": [ {
        "Effect": "Allow",
        "Principal": {
           "Service" : [ { "Fn::FindInMap": [ "Region2Principal", { "Ref": "AWS::Region" },"EC2Principal" ] } ] },
        "Action"  : [ "sts:AssumeRole" ]
      }]
    },
    "Path": "/",
    "Policies": [{
      "PolicyName": {"Fn::Join" : ["",[{"Ref":"AWS::StackName"},"InstanceApi"] ] },
      "PolicyDocument": {
        "Statement": [{
          "Effect": "Allow",
          "Action": "*",
          "Resource": "*"
        }]
      }
    }]
  }
},
Run Code Online (Sandbox Code Playgroud)