有人知道如何在无服务器框架中将 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:
设置任一道具(或两者)失败:
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 中管理,我不想吸收技术债务迁移(除非我必须这样做)
答案 0 :(得分:0)
我通过 base64 编码我的二进制数据并使用 $default
处理程序“解决”了这个问题,它允许任意数据类型