Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The policy failed legacy parsing

I am trying to create IAM Role in AWS, but while I am creating I am facing error

"We encountered the following errors while processing your request: Problem in attaching permission to role. Role will be created without permission. The policy failed legacy parsing "

{"Version": "2012-10-17",  "Statement": [
{
  "Effect": "Allow",
  "Action": [
    "logs:CreateLogGroup",
    "logs:CreateLogStream",
    "logs:PutLogEvents"
  ],
  "Resource": "arn:aws:logs:*:*:*"
},
{
  "Action": [
    "sqs:SendMessage",
    "sqs:GetQueueUrl"
  ],
  "Effect": "Allow",
  "Resource": "arn:aws:sqs:ap-northeast-1:SOME_ID_HERE:test-messages"
}]}
like image 404
Mani Teja Avatar asked Mar 27 '17 11:03

Mani Teja


3 Answers

I got this error, and couldn't figure it out. A colleague and I poured over it, and then we spotted that I had left a substitution variable without the Fn::Sub, e.g.

"Resource": "arn:aws:logs::${AWS::AccountId}:* 

will cause this error, and of course should be

"Resource": { "Fn::Sub": "arn:aws:logs::${AWS::AccountId}:*" } 

BTW, in my experience, I agree with E.J. Brennan above, you cannot use a wildcard for region, instead leave it blank as I did there.

like image 198
rubyisbeautiful Avatar answered Oct 02 '22 22:10

rubyisbeautiful


If it fails for s3, ensure that you are using the correct arn format:

  • Correct one is 3 ::: arn:aws:s3:::AccountABucketName

    "Resource": "arn:aws:s3:::AccountABucketName"

  • Wrong one 2 :: arn:aws:s3::AccountABucketName

    "Resource": "arn:aws:s3::AccountABucketName"

Count the number of colons between s3 and AccountABucketName

like image 44
aspdeepak Avatar answered Oct 02 '22 22:10

aspdeepak


If you are using serverless you can indicate that you want variables substitution by prefixing the resource with !Sub:

  Resource:
    - !Sub arn:aws:dynamodb:*:${AWS::AccountId}:table/${self:provider.environment.DYNAMODB_TABLE}

No plugin required (if serverless version is recent).

like image 41
John Mee Avatar answered Oct 02 '22 21:10

John Mee