这是我的 serverless.yml 文件:
service: investor-bot
provider:
name: aws
runtime: python3.9
stage: dev
functions:
post:
handler: handler.hello
events:
- http:
path: ita-investor-bot
method: get
这是代码(即使使用此代码也不起作用):
def hello(event, context):
return {"statusCode": 200}
我导出了我的 AWS 凭证并运行了无服务器部署:
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service investor-bot.zip file to S3 (12.77 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.......................................
Serverless: Stack update finished...
Service Information
service: investor-bot
stage: dev
region: us-east-1
stack: investor-bot-dev
resources: 11
api keys:
None
endpoints:
GET - https://933zcto8tc.execute-api.us-east-1.amazonaws.com/dev/ita-investor-bot
functions:
post: investor-bot-dev-post
layers:
None
Serverless: Removing old service artifacts from S3...
Serverless: Deprecation warning: Resolution of lambda version hashes was improved with better algorithm, which will be used in next major release.
Switch to it now by setting "provider.lambdaHashingVersion" to "20201221"
More Info: https://www.serverless.com/framework/docs/deprecations/#LAMBDA_HASHING_VERSION_V2
Toggle on monitoring with the Serverless Dashboard: run "serverless"
肯定已经部署了 API 网关。您已在 us-east-1 中部署了堆栈,我最好的猜测是您正在另一个区域使用 AWS 控制台。
登录到 AWS 控制台后,使用右上角的区域切换器切换到 us-east-1,从那里您应该可以看到 API 网关、lambda 函数和 cloudwatch 日志。
如果有人在2023年发现这个问题,我也遇到了这个问题,发现如果只定义函数(只定义处理程序),则不会创建API网关。当您将键
events
-> http
-> path
+ method
添加到函数定义中时,将创建 API 网关。