Serverless - How to create a standalone customer managed policy through serverless

Viewed 152

Currently my serverless.yml file looks like this:

service: aaaaa

provider:
  name: aws
  runtime: go1.x
  stage: mydev

resources:
  Resources:
    MyManagedPolicy:
      Type: AWS::IAM::ManagedPolicy
      Properties: 
        Description: This is my custom managed policy
        PolicyDocument:
          Version: 2012-10-17
          Statement:
            - Effect: Allow
              Action: s3:GetObject
              Resource: '*'

When I run "sls deploy" command, I am getting following error:

Error:

An error occurred: MyManagedPolicy - Syntax errors in policy. (Service: AmazonIdentityManagement; Status Code: 400; Error Code: MalformedPolicyDocument; Request ID: a20aa12c-fbaf-4301-bd20-b0148426f633).

Can you please point out the syntax error? I am new to serverless so not able to understand.

If possible please suggest the working serverless.yml

1 Answers

The MyManagedPolicy policy is correct. There is nothing wrong with its syntax, yaml nor the PolicyDocument.

To verify it, I created my own template with your MyManagedPolicy and it deployed without any issues.

However, upon tests with serverless, I can confirm that this does not work with the same issue as OP reported.

Upon further investigation it was identified that the serverless incorrectly specifies Version: 2012-10-17 as:

 "Version": "2012-10-17T00:00:00.000Z"

The solution was to use date in quotes:

Version: "2012-10-17"
Related