无服务器部署失败

时间:2019-08-19 16:06:45

标签: amazon-web-services amazon-dynamodb serverless-framework serverless aws-serverless

我正在尝试使用无服务器将lambda函数部署到AWS。执行

  

无服务器部署-详细

我每次都会收到以下错误:

  

无服务器错误---------------------------------------

     

发生错误:mainTable-无效的KeySchema:第一个> KeySchemaElement不是HASH密钥类型(服务:AmazonDynamoDBv2;状态代码:400;错误代码:ValidationException;请求ID:EACEH0RDMBR36TR0DDBGODTRT3VV4KQNSO5AEMVJF66Q9ASUAAJG)。

我的serverless.yml如下:

service: backend-1 # NOTE: update this with your service name


provider:
  name: aws
  runtime: nodejs10.x
  stage: dev
  region: eu-central-1


functions:
  graphql:
    handler: src/handler.graphql
    events:
    - http:
        path: graphql
        method: post
        cors: true

plugins:
- serverless-webpack
- serverless-offline

custom:
  webpack:
    webpackCOnfig: 'webpack.config.js'
    includeModules: true
    packager: 'npm'
  stage: ${opt:stage, self:provider.stage}

resources:
  Resources:
    mainTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: main_${self:custom.stage}
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
          - AttributeName: sort
            AttributeType: S
        KeySchema:
          - AttributeName: id
            KeyType: HASH
          - AttributeName: sort
            KeyType: RANGE
        BillingMode: PAY_PER_REQUEST
        GlobalSecondaryIndexes:
        - IndexName: spinned-primary
          KeySchema:
          - AttributeName: id
            KeyType: RANGE
          - AttributeName: sort
            KeyType: HASH
          Projection:
            ProjectionType: ALL
    labelTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: labels_${self:custom.stage}
        AttributeDefinitions:
          - AttributeName: sort
            AttributeType: S
          - AttributeName: label
            AttributeType: S
        KeySchema:
          - AttributeName: sort
            KeyType: HASH
          - AttributeName: label
            KeyType: RANGE
        BillingMode: PAY_PER_REQUEST
        GlobalSecondaryIndexes:
        - IndexName: spinned-primary
          KeySchema:
          - AttributeName: sort
            KeyType: RANGE
          - AttributeName: label
            KeyType: HASH
          Projection:
              ProjectionType: ALL
    logTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: logs_${self:custom.stage}
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
          - AttributeName: sort
            AttributeType: S
        KeySchema:
          - AttributeName: id
            KeyType: HASH
          - AttributeName: sort
            KeyType: RANGE
        BillingMode: PAY_PER_REQUEST

你们中的某人可以帮忙吗?

干杯!

1 个答案:

答案 0 :(得分:2)

使用KeySchemaElements时,HASH密钥类型必须在RANGE密钥类型之前。

在您的YAML中,对于您的主旋转GSI,您必须将HASH密钥类型放在RANGE密钥类型之前;切换它们,以便HASH是该元素中的第一个键类型。