I’m using Bedrock/Claude to stream output to a mobile app using Sockets.
I’m aware that this error occurs when we use post_to_connection within $connect, which I am not doing.
It also is known to happen when the ConnectionID changes unexpectedly.
And I know the max execution time for a Lambda function is 29 seconds. Mine executes for no more than 5-8 seconds, even when it makes this error.
"errorType": "GoneException",
"errorMessage": "UnknownError",
"name": "GoneException",
"$fault": "client",
"$metadata": {
"httpStatusCode": 410,
"requestId": "4cbe31d8-1039-40bb-b840-bed29ca70991",
"attempts": 1,
"totalRetryDelay": 0
}
My code actually works, but I’m getting this error very randomly and inconsistently. I don’t know what is causing it. Most requests work, but sometimes the very same request will cause this error. I’m not seeing any disconnect notifications on my front-end when this happens.
I do implement a keep-alive heartbeat that sends an empty request to my API-Gateway (but has no routes that do anything to my Lambda function) – this is to keep my cost down, when all I need is the socket alive, not my lambda function constantly warm.
Here is my Lambda Code
export const handler = async (event:APIGatewayProxyWebsocketEventV2):Promise<any> => {
if(event.requestContext){
const {connectionId, routeKey} = event.requestContext
var body
try {
body = (event.body)?JSON.parse(event.body):{}
} catch (error){
console.error(error)
body = {}
}
switch(routeKey){
case '$connect':
return {statusCode:200}
break;
case '$disconnect':
return {statusCode:200}
break;
case 'ask':
if(!body.payload) { return}
const _conversation:_Message[] = body.payload
const conversation:Message[] = _conversation.map((x:_Message)=>({
role:x.role,
content: [ {text: x.content} ],
}))
const command = new ConverseStreamCommand({
modelId,
messages: conversation,
inferenceConfig: { maxTokens: 512, temperature: 0.5, topP: 0.9 },
});
const response = await client.send(command);
if(response.stream){
for await (const item of response.stream) {
if (item.contentBlockDelta) {
if(item.contentBlockDelta.delta && item.contentBlockDelta.delta.text){
await gateClient.postToConnection({
ConnectionId: connectionId,
Data: item.contentBlockDelta.delta.text
})
}
}
}
await gateClient.postToConnection({
ConnectionId: connectionId,
Data: Buffer.from('//EOS//')
})
}
return {statusCode:200}
}
}
}
I have no idea how to even debug this problem. Any help is greatly appreciated.