serverless-operations / serverless-step-functions

AWS Step Functions plugin for Serverless Framework ⚡️
Other
1.03k stars 208 forks source link

API keys with values break deployment #431

Open erm410 opened 3 years ago

erm410 commented 3 years ago

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.

rbpimenta commented 10 months ago

+1