DianaIonita / serverless-api-gateway-throttling

A plugin for the Serverless framework which configures throttling for API Gateway endpoints.
ISC License
69 stars 7 forks source link

Error: Expected params.restApiId to be a string #27

Open mlewis7127 opened 1 year ago

mlewis7127 commented 1 year ago

When using this plugin with serverless framework v3 and referencing a restApi from another stack, I get an error that it expected params.restApiId to be a string.

For one stack I use the following serverless.yml file serverless.yml.zip

The next stack uses the following serverless.yml from a base aws-nodejs template: serverless.yml.zip

If I remove the throttling plugin the error message goes away.

DianaIonita commented 1 year ago

Hi @mlewis7127,

Thanks for reporting the issue. Could you please try executing sls print (reference) in your repository and checking whether the restApiId value is properly filled in?

I'll paste a sample of your yml here for easier reference and so that search engines have a chance to index it:

provider:
  name: aws
  runtime: nodejs16.x
  apiGateway:
    restApiId: !ImportValue DemoApiGW-restApiId
    restApiRootResourceId: !ImportValue DemoApiGW-rootResourceId

plugins:
  - serverless-api-gateway-throttling

custom:
  apiGatewayThrottling:
    maxRequestsPerSecond: 1000
    maxConcurrentRequests: 500
mlewis7127 commented 1 year ago

Error: Expected params.restApiId to be a string @.*** backend % sls print Running "serverless" from node_modules service: backend-issue frameworkVersion: '3' provider: name: aws runtime: nodejs16.x memorySize: 512 stage: dev region: eu-west-2 logRetentionInDays: 7 tracing: lambda: true apiGateway: restApiId: Fn::ImportValue: DemoApiGW-restApiId restApiRootResourceId: Fn::ImportValue: DemoApiGW-rootResourceId versionFunctions: true plugins:

@.*** backend % sls print --path provider.apiGateway.restApiId --format text Running "serverless" from node_modules Environment: darwin, node 14.19.2, framework 3.21.0 (local) 3.19.0v (global), plugin 6.2.2, SDK 4.3.2 Docs: docs.serverless.com Support: forum.serverless.com Bugs: github.com/serverless/serverless/issues

Error: Cannot print an object as "text"

On Thu, Jul 21, 2022 at 3:20 PM Diana Ionita @.***> wrote:

Hi @mlewis7127 https://github.com/mlewis7127,

Thanks for reporting the issue. Could you please try executing sls print (reference https://www.serverless.com/framework/docs/providers/aws/cli-reference/print) in your repository and checking whether the restApiId value is properly filled in?

I'll paste a sample of your yml here for easier reference and so that search engines have a chance to index it:

provider: name: aws runtime: nodejs16.x apiGateway: restApiId: !ImportValue DemoApiGW-restApiId restApiRootResourceId: !ImportValue DemoApiGW-rootResourceId plugins:

  • serverless-api-gateway-throttling custom: apiGatewayThrottling: maxRequestsPerSecond: 1000 maxConcurrentRequests: 500

— Reply to this email directly, view it on GitHub https://github.com/DianaIonita/serverless-api-gateway-throttling/issues/27#issuecomment-1191546541, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABK2POZWH6WVUY63LBEJUXTVVFMEFANCNFSM535RUVSA . You are receiving this because you were mentioned.Message ID: @.*** .com>

DianaIonita commented 1 year ago

Hi @mlewis7127,

From the output of your console command, it looks like there's a problem with your yaml file:

Error:
Cannot print an object as "text"

Could you please sort that out and come back with the result of sls print when there are no errors? Thanks

DianaIonita commented 1 year ago

Closing because there have been no updates on this issue in a while.

jjshinobi commented 1 year ago

Can we please re-open the issue? The error Cannot print an object as "text" is not relevant to the original issue but because of the flag --format text for the print command. The problem is that the value of restApiId is Fn::ImportValue: DemoApiGW-restApiId which the plugin can't convert to the actual id.

jjshinobi commented 1 year ago

I've found a workaround. Instead of imporing CF output variable using ImportValue we can use serverless ${cf:<stackName>.<variable key>} format. For example:

apiGateway:
    restApiId: ${cf:DemoApiGW.restApiId}
    restApiRootResourceId: ${cf:DemoApiGW.rootResourceId}
DianaIonita commented 1 year ago

Hi @jjshinobi,

Thanks for the information, I'll add it to the readme in case anyone runs into this again.