Are API Gateway Websocket Connection Ids Region-Specific?

0

We are building a multi-region application that uses websockets. It looks like we need to store the region the users connect from and use that when posting a message back to the websockets? Is that correct?

已提问 3 年前258 查看次数
1 回答
1

Hopefully helping someone else out here - storing the region, stage, and apiId from the connection and using that - we were able to get cross-region chat to work.

Example:

export interface ConnectionRecord {
connectionId: string;
userId: string;
connectedAt: string;
apiId: string;
stage: string;
region: string;
}

function getGatewayAPI(connection: ConnectionRecord) {
if (GATEWAY_APIS[connection.region]) {
return GATEWAY_APIS[connection.region];
}

const endPoint = `https://${connection.apiId}.execute-api.${connection.region}.amazonaws.com/${connection.stage}`;  

const apiGatewayManagement = new AWS.ApiGatewayManagementApi({  
    apiVersion: '2018-11-29',  
    endpoint: endPoint,  
    region: connection.region  
});  

GATEWAY_APIS\[connection.region] = apiGatewayManagement;  

return apiGatewayManagement;  

}

已回答 3 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则