serverless / examples

Serverless Examples – A collection of boilerplates and examples of serverless architectures built with the Serverless Framework on AWS Lambda, Microsoft Azure, Google Cloud Functions, and more.
https://www.serverless.com/examples/
Other
11.41k stars 4.46k forks source link

Wrong serverless-http dependency version in the basic express template #759

Open SaraPrager opened 1 year ago

SaraPrager commented 1 year ago

Are you certain it's a bug?

Is the issue caused by a plugin?

Are you using the latest v3 release?

Is there an existing issue for this?

Issue description

When installing the latest serverless version (Framework Core: 3.31.0 Plugin: 6.2.3 SDK: 4.3.2) And creating a new template by running the serverless command and choosing the "AWS - Node.js - Express API with DynamoDB" template, the following exception occurs when trying to run serverless deploy: Recoverable error occurred (Invalid character in entity name Line: 0 Column: 176 after a lot of research, chatGPT helped me to find that the serverless-http version which is ^3.1.1 by default is not compatible with serverless version 3.x. I've changed serverless-http version to ^2.6.1 per its suggestion and my issue has been solved.

Service configuration (serverless.yml) content

service: test
frameworkVersion: '3'

custom:
  profiles:
    dev: dev
    prod: prod
  tableName: 'users_table_${sls:stage}'

provider:
  name: aws
  runtime: nodejs18.x
  profile: ${self:custom.profiles.${sls:stage}}
  iam:
    role:
      statements:
        - Effect: Allow
          Action:
            - dynamodb:Query
            - dynamodb:Scan
            - dynamodb:GetItem
            - dynamodb:PutItem
            - dynamodb:UpdateItem
            - dynamodb:DeleteItem
          Resource:
            - Fn::GetAtt: [ UsersTable, Arn ]
  environment:
    USERS_TABLE: ${self:custom.tableName}

functions:
  api:
    handler: index.handler
    events:
      - httpApi: '*'

resources:
  Resources:
    UsersTable:
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      Properties:
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
        BillingMode: PAY_PER_REQUEST
        TableName: ${self:custom.tableName}

Command name and used flags

serverless deploy --verbose

Command output

Recoverable error occurred (Invalid character in entity name
Line: 0
Column: 176

Environment information

Framework Core: 3.31.0
Plugin: 6.2.3
SDK: 4.3.2
medikoo commented 1 year ago

Thanks @SaraPrager for input. Still serverless-http is used in Lambda directly, it's not a package that is run be the Framework. Do you understand why v3 of serverless-http didn't work in your lambda?