当用resources
而不是functions
用草率格式描述serverless.yml的api规范时,API不能在本地执行。
resources
中以张扬的格式进行了描述serverless.yml在下面。
functions:
test:
handler: test.test
resources:
Resources:
RestApi :
Type : AWS::ApiGateway::RestApi
Properties :
Body : ${file(./swagger.yaml)}
sls offline
的结果没有用于测试API的路由。
Serverless: Starting Offline: dev/ap-northeast-1.
Serverless: Routes for test:
Serverless: (none)
Serverless: Offline listening on http://localhost:3000
functions
中以醒目的格式描述
serverless.yml在下面。functions:
test:
handler: test.test
events:
- http: GET test
#resources:
# Resources:
# RestApi :
# Type : AWS::ApiGateway::RestApi
# Properties :
# Body : ${file(./swagger.yaml)}
sls offline
的结果具有用于测试API的路由。
Serverless: Starting Offline: dev/ap-northeast-1.
Serverless: Routes for test:
Serverless: GET /test
Serverless: Offline listening on http://localhost:3000
我想通过在资源中以醒目的格式描述规范来在本地运行API。有没有办法做到这一点?
答案 0 :(得分:1)
serverless-offline
插件了解无服务器格局,但不了解自定义AWS资源。由于无服务器是抽象层,因此将来也不太可能。
也许aws-sam-cli会更适合您的应用程序。似乎支持swagger文档和本地环境。