amazon-web-services - 无服务器框架不是通过配置在 AWS 上部署 API 网关

标签 amazon-web-services websocket aws-lambda aws-api-gateway serverless-framework

我正在尝试使用无服务器框架创建一个 Lambda,当客户端连接到 websocket API 网关时调用它。 AWS CloudFormation 正在创建已定义但未创建 websocket API 网关的 Lambda 函数。

在尝试编写自己的(不起作用)之后,我将我在无服务器文档中找到的示例复制并粘贴到新创建的无服务器文件夹中,只是为了看看它是否可以工作 - 它没有,我可以找不到其他似乎有类似问题的人。

到目前为止,我已经尝试了此处记录的简单和扩展方法(这是示例代码所基于的方法):
https://serverless.com/framework/docs/providers/aws/events/websocket/

而且我也尝试关注这个博客,这也导致了 Lambda 的创建,但没有创建 API 网关。
https://serverless.com/blog/api-gateway-websockets-example/

这是我的 serverless.yml 文件。除了 API 网关之外,它按照我的预期进行部署:

service: temp
provider:
  name: aws
  runtime: nodejs8.10
  region: eu-west-2

functions:
  default:
    handler: handler.connect
    events:
      - websocket: 
        route: $default

这是无服务器部署 -v 输出:
$ serverless deploy -v
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
CloudFormation - CREATE_IN_PROGRESS - AWS::CloudFormation::Stack - temp-dev
CloudFormation - CREATE_IN_PROGRESS - AWS::S3::Bucket - ServerlessDeploymentBucket
CloudFormation - CREATE_IN_PROGRESS - AWS::S3::Bucket - ServerlessDeploymentBucket
CloudFormation - CREATE_COMPLETE - AWS::S3::Bucket - ServerlessDeploymentBucket
CloudFormation - CREATE_COMPLETE - AWS::CloudFormation::Stack - temp-dev
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (386 B)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - temp-dev
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - DefaultLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - DefaultLogGroup
CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - DefaultLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_COMPLETE - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - DefaultLambdaFunction
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - DefaultLambdaFunction
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Function - DefaultLambdaFunction
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - DefaultLambdaVersionY0DDREbM8apFqgW7p0WqFe2SjYB4Wt7O63fYPiljU
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - DefaultLambdaVersionY0DDREbM8apFqgW7p0WqFe2SjYB4Wt7O63fYPiljU
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Version - DefaultLambdaVersionY0DDREbM8apFqgW7p0WqFe2SjYB4Wt7O63fYPiljU
CloudFormation - UPDATE_COMPLETE_CLEANUP_IN_PROGRESS - AWS::CloudFormation::Stack - temp-dev
CloudFormation - UPDATE_COMPLETE - AWS::CloudFormation::Stack - temp-dev
Serverless: Stack update finished...
Service Information
service: temp
stage: dev
region: eu-west-2
stack: temp-dev
api keys:
  None
endpoints:
  None
functions:
  default: temp-dev-default
layers:
  None

Stack Outputs
DefaultLambdaFunctionQualifiedArn: arn:aws:lambda:eu-west-2:[redacted]:function:temp-dev-default:3
ServerlessDeploymentBucketName: temp-dev-serverlessdeploymentbucket-[redacted]

如果有人能对此有所了解,因为我可能完全遗漏了一些明显的东西,我将不胜感激。

最佳答案

我遇到了完全相同的问题,对我来说,解决方案是像这样正确缩进 route:

functions:
  default:
    handler: handler.connect
    events:
      - websocket: 
          route: $default

所以基本上改变:
- websocket: 
  route: $default

至:
- websocket: 
    route: $default

关于amazon-web-services - 无服务器框架不是通过配置在 AWS 上部署 API 网关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55839068/

相关文章:

java - 我的 JAR 文件太大,无法上传到 AWS lambda

java - 线程被锁定

python - 作为 ZIP 文件调用 lambda 函数时出错

amazon-web-services - Kinesis lambda DynamoDB

node.js - 使用 AWS 生成的凭证连接到 RDS Postgres 时密码身份验证失败

python - 使用无服务器框架将库/依赖项注入(inject) AWS Lambda

java - 在 Spring Boot 应用程序中,负载均衡器请求有时会在 AWS 上意外失败

websocket - 如何在火炮负载测试脚本中创建随机字符串或数字?

ruby - 如何将数据从我的 sinatra 应用程序中的类传递到 websocket-rack?

python - Telegram bot webhook 和 amazon lambda