Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cloudformation template to create IAM role with inline policy

Tags:

I am trying to create an IAM role using the below template. I am able to create the role with managed policies. When I try to add inline policy in my template I get the error

"Property PolicyDocument cannot be empty."

{
"Resources": {
"test": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "ec2.amazonaws.com"
                ]
              },
              "Action": [
                "sts:AssumeRole"
              ]
            }
          ]
        },
        "ManagedPolicyArns": [
          "arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess",
          "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole",
        ],
      "Policies": [
      "PolicyName" : "create_snapshot",
      "PolicyDocument" : {
         "Version" : "2012-10-17",
         "Statement": [ {
         "Effect"   : "Allow",
         "Action": [
                "ec2:DeleteSnapshot",
                "ec2:CreateTags",
                "ec2:CreateSnapshot"
            ],
         "Resource" : "*"
         } ]      
      }
],
"RoleName": "test"
      }
    }
}
}    
like image 213
nad87563 Avatar asked Mar 09 '18 21:03

nad87563


People also ask

Can IAM users have inline policies attached?

Any series of permissions can be attached to an IAM entity when using an Inline Policy. Like all other policy types, Inline policies can be created using a policy editor or by writing the policy with JSON.


1 Answers

Policies is a list of policy objects which is written as follows, with each individual policy object embedded in curly braces inside the [] list:

"Policies": [ {
    "PolicyName" : "policy01",
    "PolicyDocument" : { ... }
}, {
    "PolicyName" : "policy02",
    "PolicyDocument" : { ... }
} ]
like image 161
jarmod Avatar answered Sep 21 '22 12:09

jarmod