AWS Policy must contain valid version string

Amazon Web-ServicesAmazon S3

Amazon Web-Services Problem Overview


I am getting error "This policy contains the following error: The policy must contain a valid version string For more information about the IAM policy grammar" even i included version in my policy when trying to create a new policy in AWS. My policy is

{
  "Version": "2015-06-19",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": [
        "arn:aws:s3:::repo.com",
        "arn:aws:s3:::repo.com/*"
      ]
    }
  ]
}

Amazon Web-Services Solutions


Solution 1 - Amazon Web-Services

It seems like Version is not the version of the policy that I am going to create but a set version number by AWS.

As stated by AWS documentation, version can be:

( version_block = "Version" : ("2008-10-17" | "2012-10-17")

So, I changed it to 2012-10-17 and the policy is accepted.

Solution 2 - Amazon Web-Services

According to https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html#Version:

“The Version element must appear before the Statement element. The only allowed values are these:

  • 2012-10-17. This is the current version of the policy language, and you should use this version number for all policies.
  • 2008-10-17. This was an earlier version of the policy language. You might see this version on existing policies. Do not use this version for any new policies or any existing policies that you are updating.”

Solution 3 - Amazon Web-Services

You can also generate your own policy using generate policy option that you can find in the bottom of Bucket Policy tab

enter image description here

When you click on this option you will be redirected to below-mentioned URL:

https://awspolicygen.s3.amazonaws.com/policygen.html

Solution 4 - Amazon Web-Services

I got this error using the Serverless framework.

I had Version: 2012-10-17 which was getting transformed to "Version": "2012-10-17T00:00:00.000Z"

Version: "2012-10-17" fixed it.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRaghavendraView Question on Stackoverflow
Solution 1 - Amazon Web-ServicesRaghavendraView Answer on Stackoverflow
Solution 2 - Amazon Web-ServicesDave LandView Answer on Stackoverflow
Solution 3 - Amazon Web-ServicesKartik Raja SView Answer on Stackoverflow
Solution 4 - Amazon Web-ServicestschumannView Answer on Stackoverflow