question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vague error when missing `provider.apiGateway.restApiRootResourceId` (with ``provider.apiGateway.restApiId` being configured)

See original GitHub issue

The Serverless documentation for using a shared API Gateway across stacks shows that referencing a shared API Gateway is now as simple as setting provider.apiGateway.restApiId to the gateway’s ID.

I have yet to successfully deploy a Serverless template using the described syntax. In every case CloudFormation validation fails with the error “The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource MyApiGatewayName” – in fact, the same error CloudFormation throws with old versions of Serverless/AWS CLI as well (and the same error you get if you build a similar CloudFormation template without Serverless, SAM, or AWS CLI).

I’ve tried updating Serverless, updating AWS CLI v1, and updating AWS CLI v2, testing after each change. The same error persists.

The Serverless template below defines a simple API Gateway endpoint and hardcodes an existing API Gateway ID. Just like the documentation examples, I do have a stack set up to export the API Gateway’s ID so it can be imported for use as provider.apiGateway.restApiId, but I get the same error regardless of whether I use ImportValue or hardcode the ID. To make this issue report simpler, the ID has been hardcoded.

serverless.yml
service: shared-api-gateway-bug

provider:
  name: aws
  runtime: python3.7
  region: ${opt:region, "us-east-2"}
  versionFunctions: false

  apiGateway:
    restApiId: ivrcdpj7y2 # Fn::ImportValue here results in the same error

functions:
   bugWebService:
    handler: handler.handler
    events:
      - http:
          path: /willneverbedeployed
          method: get

# The rest is just here to make the test package faster, since the full package is uploaded to AWS before CloudFormation validation throws the error
package:
  individually: false
  exclude:
    - env
    - node_modules
    - package*.json
    - "*.md"
    - "*.yml"
    - "__pycache__"
sls deploy --stage dev --profile MyProfile --aws-profile MyProfile output
(node:2604) ExperimentalWarning: The dns.promises API is experimental
(node:2604) ExperimentalWarning: The fs.promises API is experimental
Serverless: To ensure safe major version upgrades ensure "frameworkVersion" setting in service configuration (recommended setup: "frameworkVersion: ^2.11.1")

Serverless: Load command interactiveCli
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command upgrade
Serverless: Load command uninstall
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command generate-event
Serverless: Load command test
Serverless: Load command dashboard
Serverless: Load command output
Serverless: Load command output:get
Serverless: Load command output:list
Serverless: Load command param
Serverless: Load command param:get
Serverless: Load command param:list
Serverless: Load command studio
Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Invoke aws:package:finalize
Serverless: Invoke aws:common:moveArtifactsToPackage
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:deploy:deploy
Serverless: [AWS cloudformation 400 0.164s 0 retries] describeStacks({ StackName: 'shared-api-gateway-bug-dev' })
Serverless: Creating Stack...
Serverless: [AWS cloudformation 200 0.304s 0 retries] createStack({ StackName: 'shared-api-gateway-bug-dev',
  OnFailure: 'DELETE',
  Capabilities: [ 'CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM', [length]: 2 ],
  Parameters: [ [length]: 0 ],
  TemplateBody:
   '{"AWSTemplateFormatVersion":"2010-09-09","Description":"The AWS CloudFormation template for this Serverless application","Resources":{"ServerlessDeploymentBucket":{"Type":"AWS::S3::Bucket","Properties":{"BucketEncryption":{"ServerSideEncryptionConfiguration":[{"ServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}}},"ServerlessDeploymentBucketPolicy":{"Type":"AWS::S3::BucketPolicy","Properties":{"Bucket":{"Ref":"ServerlessDeploymentBucket"},"PolicyDocument":{"Statement":[{"Action":"s3:*","Effect":"Deny","Principal":"*","Resource":[{"Fn::Join":["",["arn:",{"Ref":"AWS::Partition"},":s3:::",{"Ref":"ServerlessDeploymentBucket"},"/*"]]}],"Condition":{"Bool":{"aws:SecureTransport":false}}}]}}}},"Outputs":{"ServerlessDeploymentBucketName":{"Value":{"Ref":"ServerlessDeploymentBucket"}}}}',
  Tags: [ { Key: 'STAGE', Value: 'dev' }, [length]: 1 ] })
Serverless: Checking Stack create progress...
Serverless: [AWS cloudformation 200 0.115s 0 retries] describeStackEvents({ StackName:
   'arn:aws:cloudformation:us-east-2:184140869662:stack/shared-api-gateway-bug-dev/efc40d70-28ef-11eb-90c9-0204748462f4' })
...Serverless: [AWS cloudformation 200 0.128s 0 retries] describeStackEvents({ StackName:
   'arn:aws:cloudformation:us-east-2:184140869662:stack/shared-api-gateway-bug-dev/efc40d70-28ef-11eb-90c9-0204748462f4' })
Serverless: [AWS cloudformation 200 0.11s 0 retries] describeStackEvents({ StackName:
   'arn:aws:cloudformation:us-east-2:184140869662:stack/shared-api-gateway-bug-dev/efc40d70-28ef-11eb-90c9-0204748462f4' })
Serverless: [AWS cloudformation 200 0.11s 0 retries] describeStackEvents({ StackName:
   'arn:aws:cloudformation:us-east-2:184140869662:stack/shared-api-gateway-bug-dev/efc40d70-28ef-11eb-90c9-0204748462f4' })
Serverless: [AWS cloudformation 200 0.119s 0 retries] describeStackEvents({ StackName:
   'arn:aws:cloudformation:us-east-2:184140869662:stack/shared-api-gateway-bug-dev/efc40d70-28ef-11eb-90c9-0204748462f4' })
.Serverless: [AWS cloudformation 200 0.13s 0 retries] describeStackEvents({ StackName:
   'arn:aws:cloudformation:us-east-2:184140869662:stack/shared-api-gateway-bug-dev/efc40d70-28ef-11eb-90c9-0204748462f4' })
....
Serverless: Stack create finished...
Serverless: [AWS cloudformation 200 0.114s 0 retries] describeStackResource({ StackName: 'shared-api-gateway-bug-dev',
  LogicalResourceId: 'ServerlessDeploymentBucket' })
Serverless: [AWS s3 200 0.161s 0 retries] listObjectsV2({ Bucket:
   'shared-api-gateway-bug-d-serverlessdeploymentbuck-1pel5wj7j3i0o',
  Prefix: 'serverless/shared-api-gateway-bug/dev' })
Serverless: [AWS lambda 404 0.152s 0 retries] getFunction({ FunctionName: 'shared-api-gateway-bug-dev-bugWebService' })
Serverless: [AWS sts 200 0.161s 0 retries] getCallerIdentity({})
Serverless: Uploading CloudFormation file to S3...
Serverless: [AWS s3 200 0.12s 0 retries] putObject({ Body:
   <Buffer 7b 22 41 57 53 54 65 6d 70 6c 61 74 65 46 6f 72 6d 61 74 56 65 72 73 69 6f 6e 22 3a 22 32 30 31 30 2d 30 39 2d 30 39 22 2c 22 44 65 73 63 72 69 70 74 ... >,
  Bucket:
   'shared-api-gateway-bug-d-serverlessdeploymentbuck-1pel5wj7j3i0o',
  Key:
   'serverless/shared-api-gateway-bug/dev/1605629654043-2020-11-17T16:14:14.043Z/compiled-cloudformation-template.json',
  ContentType: 'application/json',
  Metadata:
   { filesha256: '3U+sIvxlc58xy60JGNhWsY8/ASBpyZ/NS/dHby3JJIY=' } })
Serverless: Uploading artifacts...
Serverless: Uploading service shared-api-gateway-bug.zip file to S3 (5.66 KB)...
Serverless: [AWS s3 200 0.163s 0 retries] putObject({ Body:
   <Buffer 50 4b 03 04 14 00 08 00 00 00 00 00 21 00 00 00 00 00 00 00 00 00 00 00 00 00 0b 00 00 00 5f 5f 69 6e 69 74 5f 5f 2e 70 79 50 4b 07 08 00 00 00 00 00 ... >,
  Bucket:
   'shared-api-gateway-bug-d-serverlessdeploymentbuck-1pel5wj7j3i0o',
  Key:
   'serverless/shared-api-gateway-bug/dev/1605629654043-2020-11-17T16:14:14.043Z/shared-api-gateway-bug.zip',
  ContentType: 'application/zip',
  Metadata:
   { filesha256: 'BKRDpmNEUi4KkfKeG8laCXhZETz8u59IXR0Z0Ps89zI=' } })
Serverless: Validating template...
Serverless: [AWS cloudformation 400 0.368s 0 retries] validateTemplate({ TemplateURL:
   'https://s3.amazonaws.com/shared-api-gateway-bug-d-serverlessdeploymentbuck-1pel5wj7j3i0o/serverless/shared-api-gateway-bug/dev/1605629654043-2020-11-17T16:14:14.043Z/compiled-cloudformation-template.json' })
 
  Error --------------------------------------------------

  Error: The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource MyApiGatewayName
      at provider.request.catch.error (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\lib\validateTemplate.js:20:13)
  From previous event:
      at AwsDeploy.validateTemplate (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\lib\validateTemplate.js:16:85)
  From previous event:
      at AwsDeploy.BbPromise.bind.then (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\index.js:119:39)
  From previous event:
      at Object.aws:deploy:deploy:validateTemplate [as hook] (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\index.js:115:30)
      at BbPromise.reduce (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:510:55)
  From previous event:
      at PluginManager.invoke (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:510:22)
      at PluginManager.spawn (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:530:17)
      at AwsDeploy.BbPromise.bind.then (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\index.js:93:48)
  From previous event:
      at Object.deploy:deploy [as hook] (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\index.js:89:30)
      at BbPromise.reduce (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:510:55)
  From previous event:
      at PluginManager.invoke (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:510:22)
      at getHooks.reduce.then (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:545:24)
  From previous event:
      at PluginManager.run (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:545:8)
      at variables.populateService.then (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\Serverless.js:170:33)
      at runCallback (timers.js:705:18)
      at tryOnImmediate (timers.js:676:5)
      at processImmediate (timers.js:658:5)
      at process.topLevelDomainCallback (domain.js:120:23)
  From previous event:
      at Serverless.run (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\lib\Serverless.js:157:74)
      at serverless.init.then.then (C:\Users\xx\AppData\Roaming\npm\node_modules\serverless\scripts\serverless.js:50:26)

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          win32
     Node Version:              10.14.2
     Framework Version:         2.11.1
     Plugin Version:            4.1.2
     SDK Version:               2.3.2
     Components Version:        3.3.0

Installed version

(node:12492) ExperimentalWarning: The dns.promises API is experimental
(node:12492) ExperimentalWarning: The fs.promises API is experimental
Framework Core: 2.11.1
Plugin: 4.1.2
SDK: 2.3.2
Components: 3.3.0

Installed AWS CLI version

aws-cli/2.1.1 Python/3.7.7 Windows/10 exe/AMD64

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
medikoocommented, Dec 7, 2021

@sdas13 I would handle it in http event context, as those setting are specific to it. This event has dedicated validation method, so I would include it there: https://github.com/serverless/serverless/blob/4d4f8637d830ba9a72806fc127fe3497f7c0f23c/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js#L41

0reactions
sdas13commented, Dec 7, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve API Gateway REST API 403 “Missing Authentication ...
When I try to invoke my Amazon API Gateway REST API, I get 403 "Missing Authentication Token" error messages. How do I troubleshoot...
Read more >
Serverless Framework with Terraform: a firsthand experience
Then export the rest api ID and root resource ID using SSM and import/assign to the provider.apiGateway.restApiId and provider.apiGateway.
Read more >
REST API (API Gateway v1) - Serverless Framework
A missing/empty request Content-Type is considered to be the API Gateway ... same API Gateway between multiple projects by referencing its REST API...
Read more >
serverless | Yarn - Package Manager
Serverless Application Framework AWS Lambda API Gateway ... Plugins: Support variables in configuration extensions (#11558 (968ddd5 (Marco Kleinlein) ...
Read more >
AWS Serverless - Can I configure my provider or lambda ...
restApiId , Serverless Framework will generated a new API for you. To solve the problem that you described, you need to generate an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found