无服务器框架 API 网关 Websockets 二进制数据
Serverless Framework API Gateway Websockets Binary Data
有人知道如何在无服务器框架中将 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
,但我不确定如何才能完成。
这些包似乎都不处理 websockets:
- serverless-apigw-binary
- 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 中管理的,我不想吸收技术债务迁移(除非我必须这样做)
我通过 base64 编码我的二进制数据并使用允许任意数据类型的 $default
处理程序“解决”了这个问题
有人知道如何在无服务器框架中将 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
,但我不确定如何才能完成。
这些包似乎都不处理 websockets:
- serverless-apigw-binary
- 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 中管理的,我不想吸收技术债务迁移(除非我必须这样做)
我通过 base64 编码我的二进制数据并使用允许任意数据类型的 $default
处理程序“解决”了这个问题