【问题标题】:Serverless deploy fails无服务器部署失败
【发布时间】:2019-12-24 21:18:10
【问题描述】:

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

无服务器部署 --verbose

我每次都收到以下错误:

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

发生错误:mainTable - Invalid KeySchema: The first > 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

你们可以帮忙吗?

干杯!

【问题讨论】:

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


    【解决方案1】:

    使用 KeySchemaElements 时,HASH 键类型必须位于 RANGE 键类型之前。

    在您的 YAML 中,在您的 GSI 上用于 spinned-primary,您必须将 HASH 键类型放在 RANGE 键类型之前;切换它们,使 HASH 成为该元素中的第一个键类型。

    【讨论】:

      猜你喜欢
      • 2020-09-09
      • 2011-07-29
      • 1970-01-01
      • 1970-01-01
      • 2022-12-17
      • 2022-01-24
      • 1970-01-01
      • 2018-05-17
      • 1970-01-01
      相关资源
      最近更新 更多