Serverless Framework - 为dynamodb设置资源权限

Serverless Framework - Setting up resource permissions for dynamodb

我有以下 serverless.yml 文件。 我正在尝试为生成的 dynamodb 分配读写权限。

到目前为止,它生成了我的 lambda 和 dynamodb table,但是没有为 lambda 分配访问它的权限。

我没有收到任何错误,它似乎没有向 dynamodb 添加权限 table。

任何人都可以解释一下吗?

service:
  name: catcam

custom:
  stage: ${opt:stage, self:provider.stage}
  tableName: ${self:custom.stage}-notes

environment:
  tableName: ${self:custom.tableName}

plugins:
  - '@hewmen/serverless-plugin-typescript'
  - serverless-plugin-optimize
  - serverless-offline

provider:
  name: aws
  runtime: nodejs12.x
  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource:
        - { "Fn::GetAtt": ["NotesTable", "Arn" ] }
          #        - { !GetAtt NotesTable.Arn }

functions:
  main: # The name of the lambda function
    # The module 'handler' is exported in the file 'src/lambda'
    handler: src/lambda.handler
    events:
      - http:
          method: any
          path: /{any+}


resources:
  Resources:
    NotesTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${self:custom.tableName}
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: noteId
            AttributeType: S
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: noteId
            KeyType: RANGE
        # Set the capacity to auto-scale
        BillingMode: PAY_PER_REQUEST


原来上面没有错,是对的!!..是我是个香蕉人,和table的全名不符与应用程序中的环境.. 例如 notes table 变为 dev-notes.. 也许以上内容会对某人有所帮助。