【发布时间】:2021-05-11 18:37:36
【问题描述】:
有人知道如何在无服务器框架中将 websocket 的内容处理策略设置为二进制吗?
我有一个 websocket 定义如下:
my_websocket:
handler: src/handler.handler
description: My websocket
events:
- websocket:
route: $default
- websocket:
route: $connect
- websocket:
route: $disconnect
我的处理程序需要二进制数据
我需要将我的ContentHandling 或ContentHandlingStrategy 设置为CONVERT_TO_BINARY,但我不确定如何实现。
这些软件包似乎都不能处理 websocket:
- 无服务器-apigw-二进制
- serverless-apigwy-binary
设置任一道具(或两者)失败:
events:
- websocket:
route: $default
ContentHandling: CONVERT_TO_BINARY
ContentHandlingStrategy: CONVERT_TO_BINARY
- websocket:
route: $connect
ContentHandling: CONVERT_TO_BINARY
ContentHandlingStrategy: CONVERT_TO_BINARY
- websocket:
route: $disconnect
ContentHandling: CONVERT_TO_BINARY
ContentHandlingStrategy: CONVERT_TO_BINARY
如下:
Serverless: Configuration warning:
Serverless: at 'functions.my_websocket.events[0].websocket': unrecognized property 'contentHandling'
Serverless: at 'functions.my_websocket.events[0].websocket': unrecognized property 'ContentHandlingStrategy'
Serverless: at 'functions.my_websocket.events[1].websocket': unrecognized property 'contentHandling'
Serverless: at 'functions.my_websocket.events[1].websocket': unrecognized property 'ContentHandlingStrategy'
Serverless: at 'functions.my_websocket.events[2].websocket': unrecognized property 'contentHandling'
Serverless: at 'functions.my_websocket.events[2].websocket': unrecognized property 'ContentHandlingStrategy'
值得注意的是,使用 cdk 可以(由朋友)实现,如下所示:
const messageIntegration = new CfnIntegration(this, `${name}-message-route-lambda-integration`, {
apiId: api.ref,
integrationType: 'AWS_PROXY',
integrationUri: 'arn:aws:apigateway:' + config['region'] + ':lambda:path/2015-03-31/functions/' + messageFunc.functionArn + '/invocations',
credentialsArn: role.roleArn,
contentHandlingStrategy: 'CONVERT_TO_BINARY', // see http://amzn.to/39DkYP4
})
我正在寻找一种 sls 方法,因为我所有的基础设施都是在 sls 中管理的,我不想承担迁移的技术债务(除非我必须这样做)
【问题讨论】:
-
点赞。这个问题非常清楚和详细。回到这个问题,我认为 sls 还没有此选项可用于转换为二进制文件。也许将来,他们可能会根据要求引入
标签: websocket binary aws-api-gateway serverless-framework