Predictable URLs for Lambda API testing

Hi all,

I am attempting to host a lambda at a predictable location with serverless-localstack, which works well for local testing. However, the same configuration seems to create an error when deploying remotely to AWS.

The difference seems to be around adding the restApiId attribute…

    apiGateway: {
      restApiId: "myrest",
      minimumCompressionSize: 1024,
      shouldStartNameWithService: true,
    },

When I set this string value it helps me by ensuring the lambda is at a predictable location for integration testing, which proves the id is successfully read as the tests run successfully against http://localhost:4566/restapis/myrest/local/_user_request_/dev

However, when deploying to AWS with the same configuration, the deployment fails with…

The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource ApiGatewayRestApi

Any suggestions for how I get a predictable location for the endpoint for testing but while still being able to deploy to AWS Lambda?

A workaround might be to know how to calculate or get the full URL of a lambda deployment, but unfortunately that is performed by a separate console operation than the (jest) test runner so getting them to talk could be hard.

How do people solve this problem?