serverless-step-functions icon indicating copy to clipboard operation
serverless-step-functions copied to clipboard

Failing to package when API keys is an array of objects - version 3.2.0

Open danielhorne opened this issue 4 years ago • 4 comments

This is a Bug Report with regards to trying to package/deploy with when specifying an API key in version 3.2.0

Description

I have a typescript serverless project setup. This has been packaging perfectly until I updated serverless-step-function from version 3.0.0 to 3.2.0

What went wrong

My packaging is failing with the following error - API Keys must be strings. I had to roll back serverless-step-functions from version 3.2.0 to 3.0.0

Stack Trace

ServerlessError: API Keys must be strings
      at C:\Users\CT301547.CAPITECBANK\repos\databus-serverless\node_modules\serverless-step-functions\lib\deploy\events\apiGateway\apiKeys.js:19:17
      at arrayEach (C:\Users\CT301547.CAPITECBANK\repos\databus-serverless\node_modules\lodash\lodash.js:530:11)
      at Function.forEach (C:\Users\CT301547.CAPITECBANK\repos\databus-serverless\node_modules\lodash\lodash.js:9410:14)
      at ServerlessStepFunctions.compileApiKeys (C:\Users\CT301547.CAPITECBANK\repos\databus-serverless\node_modules\serverless-step-functions\lib\deploy\events\apiGateway\apiKeys.js:15:9)
      at ServerlessStepFunctions.tryCatcher (C:\Users\CT301547.CAPITECBANK\repos\databus-serverless\node_modules\bluebird\js\release\util.js:16:23)
      at Promise._settlePromiseFromHandler (C:\Users\CT301547.CAPITECBANK\repos\databus-serverless\node_modules\bluebird\js\release\promise.js:547:31)
      at Promise._settlePromise (C:\Users\CT301547.CAPITECBANK\repos\databus-serverless\node_modules\bluebird\js\release\promise.js:604:18)
      at Promise._settlePromise0 (C:\Users\CT301547.CAPITECBANK\repos\databus-serverless\node_modules\bluebird\js\release\promise.js:649:10)
      at Promise._settlePromises (C:\Users\CT301547.CAPITECBANK\repos\databus-serverless\node_modules\bluebird\js\release\promise.js:729:18)
      at _drainQueueStep (C:\Users\CT301547.CAPITECBANK\repos\databus-serverless\node_modules\bluebird\js\release\async.js:93:12)
      at _drainQueue (C:\Users\CT301547.CAPITECBANK\repos\databus-serverless\node_modules\bluebird\js\release\async.js:86:9)
      at Async._drainQueues (C:\Users\CT301547.CAPITECBANK\repos\databus-serverless\node_modules\bluebird\js\release\async.js:102:5)
      at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\CT301547.CAPITECBANK\repos\databus-serverless\node_modules\bluebird\js\release\async.js:15:14)
      at processImmediate (internal/timers.js:461:21)

Serverless setup

Here is how I have my api keys setup

provider:{
        apiGateway: {
            restApiId: '${file(./config/${opt:stage}.json):restApiId}',
            restApiRootResourceId: '${file(./config/${opt:stage}.json):restApiRootResourceId}',
            apiKeys: [{ name: 'sls-api-key', value: '${ssm:/ds-databus/${opt:stage}/api-key/sls~true}' }],
        },
}

The issue is in apiKeys.js line 13 - 18


_.forEach(this.serverless.service.provider.apiKeys, (apiKey, i) => {
        const apiKeyNumber = i + 1;

        if (typeof apiKey !== 'string') {
          throw new this.serverless.classes.Error('API Keys must be strings');
}

With my setup apiKey is an object containing name and value and therefor fails to satisfy the condition. There looks like there was some update between 3.0.0 and 3.2.0 which has caused this break. This condition needs to be updated to cater for objects

Additional Data

  • Serverless Framework Core Version: 2.66.2
  • The Plugin Version you're using: 3.2.0
  • Operating System: Windows 10

Just wanted to a chance to thank you guys for an awesome plugin

danielhorne avatar Nov 23 '21 14:11 danielhorne

I'm interested in this issue as my code also fails. I hope it will be fixed.

DogFortune avatar Dec 13 '21 00:12 DogFortune

My apiKeys defined is the same I hope the code that compiles ApiKeys will be fixed..

tttaisgt avatar Jun 07 '23 05:06 tttaisgt

+1

rbpimenta avatar Jan 05 '24 14:01 rbpimenta