serverless-iam-roles-per-function icon indicating copy to clipboard operation
serverless-iam-roles-per-function copied to clipboard

Can't rename role name using iamRoleStatementsName

Open ghost opened this issue 5 years ago • 1 comments

I use this in multiple modules, but for some reason it isn't working in a new module and I can't figure out why. Here's my serverless.yml file

service: 
  name: ${self:custom.provider.service}-device-notification-handler

plugins:
  - serverless-export-env
  - serverless-iam-roles-per-function
  - serverless-webpack
  - serverless-offline

package:
  individually: true
  exclude:
    - node_modules/**

provider:
  name: aws
  runtime: nodejs12.x
  region: ${self:custom.provider.regions.${self:custom.stage}}
  profile: ${self:custom.provider.profile}
  stage: dev

custom:
  webpack:
    webpackConfig: ./webpack.config.js
    includeModules: true

functions:
  helloWorld:
    handler: src/hello.main
    iamRoleStatementsName: hello-world-lambdaRole
    iamRoleStatements:
      - Effect: "Allow"        
        Action:
          - dynamodb:GetItem        
        Resource: "*"

And when I run it I get the following error:

An error occurred: IamRoleLambdaExecution - 1 validation error detected: Value 'smartwater-device-notification-handler-dev-ca-central-1-lambdaRole' at 'roleName' failed to satisfy constraint: Member must have length less than or equal to 64

And here's my package.json dependencies:

"serverless": "^1.60.4", "serverless-iam-roles-per-function": "^2.0.2"

ghost avatar Feb 03 '20 20:02 ghost

This is weird, since you are passing iamRoleStatementsName, its value should be used before actually running code which actually returns a composed name of the role eg.: smartwater-device-notification-handler-dev-ca-central-1-lambdaRole. By the way its 66 chars long, so by shortening for example service name by 2 characters to get it to 64 chars should make it pass.

I have tried it on a quick prototype to set a custom role name as you above and it went through without a problem.

itskemo avatar Feb 18 '20 12:02 itskemo