functionalone / serverless-iam-roles-per-function

Serverless Plugin for easily defining IAM roles per function via the use of iamRoleStatements at the function level.
MIT License
411 stars 58 forks source link

Global Role Name is not in expected format #100

Open ghost opened 2 years ago

ghost commented 2 years ago

I have the following serverless.yml (snippet)

  iam:
    role:
      name: ${self:provider.stage}-${self:service.name}-default-role
      statements:
        - Effect: Allow
          Action:
            - ssm:GetParameter
            - ssm:GetParameters
          Resource:
            - !Sub "arn:aws:ssm:${self:provider.region}:${AWS::AccountId}:parameter/${self:provider.stage}/*"

And when trying to deploy I get:

ERROR: Global Role Name is not in expected format. Got name: "test-rest-ra-gui-apis-default-role"

This used to work up until some time ago (maybe I updated serverless or the plugin inadvertently)

Looking at the source code it's doing:

    const roleName = this.serverless.providers.aws.naming.getRoleName();
    const fnJoin = roleName['Fn::Join'];

And checking some things on fnJoin, which puzzles me because I didn't find in the documentation any reference to it

Any clues?

Thanks

juantula commented 1 year ago

The problem happens when the function hasiamRoleStatements value set (even an empty array). To avoid the issue, you also need to specify a value in iamRoleStatementsName.