我正在使用SAM CLI开发API Gateway Lambda代理集成。根据文档,我应该能够使用sam local start-api
在本地测试我的端点。 start-api
命令允许进行“热重载”,如 AWS SAM文档中所述 。但是,我没有看到这种行为。
我的template.yaml
文件看起来像:
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
Architectures:
- x86_64
Events:
HelloWorld:
Type: Api
Properties:
Path: /hello
Method: get
Metadata:
Dockerfile: Dockerfile
DockerContext: ./hello_world
DockerTag: python3.9-v1
当我执行以下命令:
> sam build && sam local start-api
我能看到端点正在工作:
将HelloWorldFunction挂载在http://127.0.0.1:3000/hello
您现在可以浏览以上端点来调用您的函数。在编写函数时,您无需重新启动/重新加载SAM CLI,更改将立即/自动反映。
然而,当我更改./hello_world/app.py
中的lambda_handler
函数时,对curl http://localhost:3000
的响应仍然保持不变。没有热加载发生。
我找到的唯一解决办法是为每个代码更改运行sam build
。由于requirements.txt
中包含某些依赖项,这会严重拖慢开发时间--我必须等待每个代码更改的构建1-2分钟。我可以只在.aws-sam/build
目录中的文件上工作--就像这里建议的那样--但这似乎是一个不好的解决方案,因为我必须同时维护两个处理程序副本。