Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mlewis7127 opened this issue Jul 18, 2022 · 7 comments
Open

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

mlewis7127 opened this issue Jul 18, 2022 · 7 comments

Comments

@mlewis7127
Copy link

mlewis7127 commented Jul 18, 2022

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
Copy link
Owner

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
Copy link
Author

mlewis7127 commented Jul 21, 2022 via email

@DianaIonita
Copy link
Owner

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
Copy link
Owner

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

@jjshinobi
Copy link

jjshinobi commented Oct 4, 2022

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
Copy link

jjshinobi commented Oct 5, 2022

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
Copy link
Owner

Hi @jjshinobi,

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

@DianaIonita DianaIonita reopened this Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants