Skip to content

API keys with values break deployment #431

@erm410

Description

@erm410

Plugin version: 2.30.0
Serverless versions: 2.0.0 and 2.11.1

When using an api key definition that is not a simple string, deployment fails

serverless.yml

provider:
  name: aws
  apiKeys:
    - name: myKey
      value: myKeyValue

output

API Keys must be strings

It appears that the plugin does not handle the longer form of the API key definition. Extracting the name from the api key (if it exists) seems to work around the problem.

Here is the diff that solved my problem:

diff --git a/node_modules/serverless-step-functions/lib/deploy/events/apiGateway/apiKeys.js b/node_modules/serverless-step-functions/lib/deploy/events/apiGateway/apiKeys.js
index fe635fd..7f1dbe0 100644
--- a/node_modules/serverless-step-functions/lib/deploy/events/apiGateway/apiKeys.js
+++ b/node_modules/serverless-step-functions/lib/deploy/events/apiGateway/apiKeys.js
@@ -13,6 +13,8 @@ module.exports = {
       _.forEach(this.serverless.service.provider.apiKeys, (apiKey, i) => {
         const apiKeyNumber = i + 1;
 
+        apiKey = apiKey.name || apiKey;
+
         if (typeof apiKey !== 'string') {
           throw new this.serverless.classes.Error('API Keys must be strings');
         }
diff --git a/node_modules/serverless-step-functions/lib/deploy/events/apiGateway/usagePlanKeys.js b/node_modules/serverless-step-functions/lib/deploy/events/apiGateway/usagePlanKeys.js
index ff22f2b..a9bbb03 100644
--- a/node_modules/serverless-step-functions/lib/deploy/events/apiGateway/usagePlanKeys.js
+++ b/node_modules/serverless-step-functions/lib/deploy/events/apiGateway/usagePlanKeys.js
@@ -13,6 +13,8 @@ module.exports = {
       _.forEach(this.serverless.service.provider.apiKeys, (apiKey, i) => {
         const usagePlanKeyNumber = i + 1;
 
+        apiKey = apiKey.name || apiKey;
+
         if (typeof apiKey !== 'string') {
           throw new this.serverless.classes.Error('API Keys must be strings');
         }

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions