A workaround would be to use CloudFront distribution in front of the websocket API and serve the requests via CloudFront distribution. Meaning custom domain name can be created for websocket API that will be served via CloudFront dist. The origin of the CloudFront dist would be the websocket API endpoint
https://aws.amazon.com/about-aws/whats-new/2018/11/amazon-cloudfront-announces-support-for-the-websocket-protocol/
Lambda@Edge function can be triggered on 'Origin Request' event and the function can strip the hardware id from the URL and pass it as queryString or header etc to the websocket API. The backend of the websocket API can access queryString/header and eventually get hardware id from the incoming event data
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-cloudfront-trigger-events.html
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-examples.html#lambda-examples-redirecting-examples
Note: DNS record(CNAME) is required to map the Domain Name to CloudFront dist
Sample L@E nodeJs code below:
'use strict';
exports.handler = (event, context, callback) => {
console.log(event)
const request = event.Records[0].cf.request;
var hardwareId = request.uri.substr(1);
request.origin = {
custom: {
domainName: 'xxxxxxxxxx.execute-api.us-east-1.amazonaws.com',
port: 443,
protocol: 'https',
path: '/dev',
sslProtocols: ['TLSv1', 'TLSv1.1','TLSv1.2'],
readTimeout: 60,
keepaliveTimeout: 5,
customHeaders: {}
}
};
request.uri = '/';
request.querystring = 'hardwareId='+hardwareId;
callback(null, request);
};