Serverless Framework - Настройка разрешений для ресурсов для DynamodB - PullRequest
1 голос
/ 16 февраля 2020

У меня есть следующий serverless.yml файл. Я пытаюсь назначить разрешения на чтение и запись для сгенерированной DynamodB ..

Пока что она генерирует мою лямбду и таблицу DynamodB, но у лямбды нет назначенных разрешений для доступа к ней.

Я не получаю ошибок, и, похоже, он не добавляет разрешения в таблицу DynamodB.

Может кто-нибудь пролить свет, пожалуйста?

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


1 Ответ

0 голосов
/ 17 февраля 2020

Оказывается, с вышесказанным все в порядке, это правильно !! .. это я был бананом и не сопоставлял полное имя таблицы с окружающей средой в приложении .. т.е. Например, 1003 * notes table становится dev-notes .. возможно, вышеизложенное поможет кому-то.

...