简体   繁体   English

SAM-local 无法使用多个堆栈启动 API

[英]SAM-local fails to start API with multiple stacks

I want to add resources to my root stack and somehow found a function where I can first get stack first like this我想将资源添加到我的根堆栈,并以某种方式找到了一个 function,我可以首先像这样首先获取堆栈

   my_api = RestApi.from_rest_api_attributes(self, "RestApi",
                                               rest_api_id='test',
                                               root_resource_id='test'
                                

           )

reference https://docs.aws.amazon.com/cdk/api/v1/python/aws_cdk.aws_apigateway/README.html#breaking-up-methods-and-resources-across-stacks参考https://docs.aws.amazon.com/cdk/api/v1/python/aws_cdk.aws_apigateway/README.html#breaking-up-methods-and-resources-across-stacks

and then trying to add resources after getting this stack然后在获取此堆栈后尝试添加资源

mine_ = my_api.root.add_resource("mine")
mine_.add_method(
            http_method='GET',
            authorizer=api_authorizer
        )

on this I am getting this error对此我收到了这个错误

ValueError: urls must start with a leading slash ValueError:网址必须以斜杠开头

any help would be highly appreciated..任何帮助将不胜感激..

Edit full traceback of error:编辑错误的完整回溯:

Traceback (most recent call last):
  File "samcli/__main__.py", line 12, in <module>
  File "click/core.py", line 829, in __call__
  File "click/core.py", line 782, in main
  File "click/core.py", line 1259, in invoke
  File "click/core.py", line 1259, in invoke
  File "click/core.py", line 1066, in invoke
  File "click/core.py", line 610, in invoke
  File "samcli/lib/iac/utils/helpers.py", line 55, in wrapper
  File "samcli/commands/_utils/iac_validations.py", line 79, in wrapped
  File "click/decorators.py", line 73, in new_func
  File "click/core.py", line 610, in invoke
  File "samcli/lib/telemetry/metric.py", line 174, in wrapped
  File "samcli/lib/telemetry/metric.py", line 141, in wrapped
  File "samcli/lib/utils/version_checker.py", line 42, in wrapped
  File "samcli/cli/main.py", line 90, in wrapper
  File "samcli/commands/local/start_api/cli.py", line 128, in cli
  File "samcli/commands/local/start_api/cli.py", line 205, in do_cli
  File "samcli/commands/local/lib/local_api_service.py", line 68, in start
  File "samcli/local/apigw/local_apigw_service.py", line 173, in create
  File "flask/app.py", line 98, in wrapper_func
  File "flask/app.py", line 1275, in add_url_rule
  File "werkzeug/routing.py", line 666, in __init__
ValueError: urls must start with a leading slash
[8038] Failed to execute script __main__

urls must start with a leading slash is not an error that CDK throws. urls must start with a leading slash不是 CDK 抛出的错误。 It's a werkzeug error, you can see the code in question here .这是一个 werkzeug 错误,您可以在此处查看有问题的代码。

So the error doesn't have anything to do with your CDK code.所以这个错误与你的 CDK 代码没有任何关系。

The reason for the error is that SAM does not support testing multiple stacks at this point.错误的原因是 SAM 不支持此时测试多个堆栈。 So either compile everything into a single stack, or avoid using sam-beta-cdk .因此,要么将所有内容编译到一个堆栈中,要么避免使用sam-beta-cdk

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Lambda 的 AWS SAM API 端点在使用“sam start local-api”在本地运行时抛出错误 - AWS SAM API endpoint using a Lambda is throwing error when it runs locally with "sam start local-api" AWS SAM 本地启动 API 无法解析 Fn::ImportValue - AWS SAM local start-api cannot resolve Fn::ImportValue sam local start-api go lambda 在 linux ubuntu 上返回 502“内部服务器错误” - sam local start-api go lambda returns 502 "internal server error" on linux ubuntu 无法将 AWS SAM 本地 API 连接到在 docker 实例中运行的 dynamodb-local - Unable to connect AWS SAM local API to dynamodb-local running in docker instance AWS SAM - 本地 api 调用以返回事件的版本 2 - AWS SAM - local api call to return version 2 of the event SAM 部署失败并出现大小问题 Lambda Function - SAM Deployment Fails with Size Issue For Lambda Function 在定义单个 AWS::Serverless::Function 的 SAM 模板中指定多个 API 阶段和 Lambda 别名 - Specify multiple API stages and Lambda Aliases in SAM template defining a single AWS::Serverless::Function 卓:如何使用“sam local”写入本地文件系统? - AWS: How to write to the local file system with 'sam local'? 使用 sam init 部署 AWS Lambda“Hello World”,sam build sam deploy defaults 失败,无法为 sam-app 创建变更集 - Deploying AWS Lambda "Hello World" using sam init, sam build sam deploy defaults fails with Failed to create changeset for sam-app VS Code 和 AWS SAM 本地调用问题 - VS Code & AWS SAM local invoke issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM