I am using AWS websocket api gateway and I can get a connection id from the request context. The connection id is a websocket id which I need to save in our database for connection management.
What I am not sure is whether the connection id is unique? Is it possible to get a duplicate connection id when my application is running for a few years?
yes the connectionId value provided in the context object is unique,
from the docs
API Gateway WebSocket API mapping template reference
$context.connectionId -> A unique ID for the connection that can be used to make a callback to the client.
Related
I have build a API gateway stack that allows clients to connect and push data into a kinesis data stream.
I have a custom authentication lambda that runs on the initial connection which correctly validates the user. The session information is then written into dynamoDB along with some other process data that I would like to return to the client before it the client starts to send data to websocket $default route.
I've added a lambda to the $connect route and tried in both the authorization and connect lambda functions to return data via headers, directly, and through the apigateway #connections method but none of these method work, and the connection isn't yet established to be able to send data back down to the client.
Is this possible? Or would the only way to achieve this be to delay the response through an SQS queue, or to have the client request the data in someway before it starts?
**I have created realtime activities website.
currently my website is like this:
frontend page created websocket with endpoint url wss://xyz.com/chat/$scope.userId
In my backend i store a map table of userId-Websocketconnection
when anyone likes image of userId-5 , backend sends notification to websocketConnection whose userId is 5
But now i want to use Aws websocket api
i am confused at several points
how to send userId with websocket connection request to aws websocket api
using aws websocket api ,how can i store this connectionid and user id in my springboot database
when someone likes image of userId-5 , how will i send notification to websocket connection of userId-5
Is it possible using aws websocket api. Please help me
**
That's what exactly APIGateway websocket protocol offers.
You need to connect to websocket, then send a message (json) which has userid in it. Example message below.
{"action": "SUBSCRIBE","payload": {"userId":"123"}}
On APIGateway you can create SUBSCIRBE route and map it to backend endpoint as Integration request where you store connection id into database.
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-integration-requests.html
Whenever your spring boot application wants to push notifications, you can make use of AmazonApiGatewayManagementApi and broadcast the message.
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html
Does API gateway support using consistent hash on a request parameter to select the upstream backend to route the request to?
Something like:
https://www.nginx.com/resources/wiki/modules/consistent_hash/
I want all requests matching a certain criteria, identified through the hash of request, to be sent to same backend server. For example, if I have 5 different backend servers and have 1 million end users send requests wit 5 different IDs in the url, then I want each backend server to process requests with just 1 ID.
I'm not aware of this option on API Gateway directly.
However, quite in complicated way, you can integrate API Gateway with the ALB. Then, in ALB, you can configure multiple listeners with rules requiring the desired hashes in request query parameter. For each of those listeners you will assign a target group with the backend server instance.
See documentation for details
https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-private-integration.html
https://docs.aws.amazon.com/elasticloadbalancing/latest/network/create-listener.html
https://docs.aws.amazon.com/elasticloadbalancing/latest/network/target-group-register-targets.html
I'd really appreciate any advice on the following. Building a real-time infrastructure for android mobile devices to connect to windows POS systems.
POS system will run a .NET app that will connect to AWS WebSocket API Gateway and register with a storeId.
Android device will call an AWS HTTP API Gateway endpoint to retrieve POS information from the store.
Here's the part I'm not sure about. I'd like the AWS HTTP endpoint to trigger a lambda function that will lookup the websocket connectionId from the storeId and send a message to the connected store and wait for a new message from the store. The store client would receive the websocket message, collect the info, then send it to dynamodb and then notify the original lambda function that the data is ready to send back.
Can lambda do that? Connect to another websocket api, wait for a message, then disconnect, and eventually return the original HTTP API request to the android client? Am I going down the wrong path?
Is there a better way for an AWS HTTP API endpoint to send a message to a websocket client and get a response?
My other approach was to have the android client connect via websocket as well. Send request messages back and forth via websocket, and then call http api to upload / download larger data payloads. But would still like to find some way to provide HTTP API to others in order to retrieve the store data via the websocket client.
Looking for some help regarding outbound calling.
Using the article https://aws.amazon.com/blogs/contact-center/identify-and-move-unwelcomed-calls-on-your-amazon-connect-instance/
I have created a function that will block/play message to customers if number exists in a sql table for inbound calls.
My main goal however is outbound calling - blocking UK-CTPS or US-DoNotCall database.
I want to check the number dialed against the DB before the call is connected - then proceed if number does not exist, or terminate the call if number does exist.
There appears to be little documentation regarding outbound calling flows.
I can set up the flow to check the number after the call has connected, but need it to work prior to the call, obviously.
Thanks
When an outbound contact is initiated in Amazon Connect, the dial request is processed immediately and then connected to a contact flow after the call is setup. This means that there is no opportunity to defeat the dialing request after the dialing client has sent the request. If you need to process logic to deny the dialing request, it would need to be done in the client prior to the request being sent to then Amazon Connect APIs.
There are 2 APIs that allow contacts to be created/initiated; the one that is used by web-based interfaces (like the Amazon Connect Contact Control Panel) which agents use, and the Outbound API that is part of the AWS SDK (which is meant for automated dialing applications). If your use case is preventing agents from dialing numbers on Do Not Call lists, then you can use the Streams API to create a custom dialing interface for the agents and only allow the dialing request to be sent after you check your Do Not Call blacklist.
You could use Amazon API Gateway to expose an HTTP interface to your Lambda code using the Lambda Proxy (see documentation here). When an agent clicks the dial button in your custom interface, you can call the API Gateway method to check the number against your DNC list. If the number is not found in the DNC list, then you would process the dialing request with the agent.connect() function of the Streams API (example below).
agent.connect(Endpoint.byPhoneNumber("5558675309"), {
success: function() { ... },
failure: function() { ... }
});