Identifying and Removing Clients in AWS API Gateway WebSocket APIs

DVA-C02 By islever Editorial Last updated

Use data stores in application development. Assist in a root cause analysis.

Short answer

CE Use the callback URL to disconnect the client from the backend service and implement $connect and $disconnect routes in the backend service.

Question

A real-time messaging application uses Amazon API Gateway WebSocket APIs with backend HTTP service. A developer needs to build a feature in the application to identify a client that keeps connecting to and disconnecting from the WebSocket connection. The developer also needs the ability to remove the client.
Which combination of changes should the developer make to the application to meet these requirements? (Choose two.)
  1. Switch to HTTP APIs in the backend service.
  2. Switch to REST APIs in the backend service.
  3. Use the callback URL to disconnect the client from the backend service. Correct Answer
  4. Add code to track the client status in Amazon ElastiCache in the backend service.
  5. Implement $connect and $disconnect routes in the backend service. Correct Answer

Key Takeaways

The trap is selecting storage options (like ElastiCache) without the action mechanism (callback URL), failing to meet the 'remove client' requirement.

To identify and remove problematic clients in AWS API Gateway WebSocket APIs, developers should implement $connect and $disconnect routes for tracking and use the callback URL to force disconnection.

Common mistake: Choosing D and E is a common mistake because it addresses identification but completely misses the requirement to actively remove the client, which requires the callback URL.

Expert Analysis

The scenario requires two distinct capabilities: identifying a problematic client based on connection patterns and actively removing that client from the WebSocket session. To meet these requirements, the developer must leverage specific features of Amazon API Gateway WebSocket APIs.

First, to identify a client that keeps connecting and disconnecting, the application needs to track these events. AWS API Gateway provides reserved routes for this exact purpose: $connect and $disconnect. Implementing these routes allows the backend service (e.g., a Lambda function) to receive notifications when clients join or leave. By logging these events to a persistent store like Amazon ElastiCache or DynamoDB, the backend can analyze patterns to identify the "spammer" or unstable client. Without these routes, the backend has no native mechanism to detect connection lifecycle events automatically. Therefore, implementing $connect and $disconnect routes is essential for identification and tracking.

Second, to remove the identified client, the backend service needs a way to force-disconnect them. API Gateway provides a callbackUrl when a message is sent to a connected client. This URL can be used by the backend to send a control message back to the client, which can include instructions to close the connection or simply trigger a disconnection event. Using the callback URL is the standard programmatic method to interact with and potentially terminate specific WebSocket connections from the backend. Thus, using the callback URL is the correct mechanism for removal.

Let's evaluate why other options are incorrect:

  • Switching to HTTP or REST APIs (Options A and B) would break the real-time messaging capability entirely, as these protocols do not support persistent WebSocket connections.
  • While storing status in ElastiCache (Option D) supports the tracking aspect, it does not address the requirement to remove the client. Furthermore, without the $connect/$disconnect routes, you cannot reliably populate that cache with accurate connection state data. Option E is more fundamental because it enables the detection logic itself. However, looking at the official AWS documentation and exam patterns, the combination of tracking via routes and acting via callback is the complete solution. Wait, let's re-read carefully. The question asks for a combination of changes.

Actually, there is a nuance. The callbackUrl is generated when sending a message. To disconnect, you typically send a message with a specific payload or use the Disconnect action if available via the API Gateway API. However, the most direct way to handle the lifecycle is via the reserved routes. Let's look at the options again.

Option C says "Use the callback URL to disconnect the client". This is technically how you communicate with a specific client ID to tell them to disconnect or to trigger a disconnect. Option E says "Implement $connect and $disconnect routes". This is how you identify the behavior.

Is D necessary? You need a place to store the count of connections. But E gives you the events. D gives you the storage. If you have E but no D, you can't persist the history to identify the pattern over time easily unless you log elsewhere. But the question implies building a feature to identify.

Let's reconsider the standard answer for this type of question. Usually, identifying requires tracking (Storage + Events) and removing requires an action. However, many sources point to C and E. Why? Because $connect/$disconnect routes allow you to manage the connection state and trigger backend logic. The callback URL allows you to send messages to specific clients, including commands to disconnect.

Wait, another perspective: Can you disconnect a client without a callback URL? No, you need to send a message to their connection ID. So C is required for removal. For identification, you need to know who is connecting/disconnecting. That comes from the $connect and $disconnect routes (E). You don't necessarily need ElastiCache if you just want to react in real-time or if the identification is immediate (e.g., if they disconnect immediately after connect repeatedly). But the question says "keeps connecting", implying a pattern.

Let's look at the comments. Most users voted DE or CE. If I choose D and E: I track in ElastiCache and use routes. But how do I remove them? D and E don't provide a mechanism to remove the client. They only help identify. The question explicitly asks for the ability to remove the client. Neither D nor E removes the client. Therefore, D+E is incomplete.

If I choose C and E: E ($connect/$disconnect) helps identify the behavior (by triggering backend code that analyzes the stream of events). C (Callback URL) allows the backend to send a message to the client to disconnect them. This covers both requirements: Identification (via E triggering analysis) and Removal (via C).

Therefore, C and E are the correct pair. C handles the 'remove' part. E handles the 'identify' part (by providing the hooks to observe the behavior).

Common Mistake: Choosing D and E. This fails because while D and E help identify, they lack the mechanism to actually disconnect/remove the client. The question demands both identification AND removal.

Official Reference

Exam Strategy

When answering questions requiring both observation and action, ensure your selected options cover both aspects. If one option group handles monitoring (routes/events) and another handles execution (API calls/callbacks), select the pair that completes the full workflow. Never assume a monitoring tool alone satisfies an action-oriented requirement.

Frequently Asked Questions

Why isn't ElastiCache sufficient for identifying clients?

ElastiCache stores data but doesn't generate the events needed to identify connection patterns. You need the $connect and $disconnect routes to capture those events.

How does the callback URL disconnect a client?

The callback URL allows the backend to send a message to a specific client's connection ID. Sending a specific payload or command through this URL can trigger the client to close the connection.

More DVA-C02 FAQ →

Community Votes

E
45%
C
34%
D
21%

45% of anonymous learners picked answer E. Votes are pick records left by other test-takers — they are not the verified answer.

Discussion 34 contributions

Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.

From public community threads 30 of 34

  1. MrTee 👍 22
    Option D because by storing the client status in the cache, the backend service can quickly access the client status data without the need to query the database or perform other time-consuming operations. Option E. Implement $connect and $disconnect routes in the backend service: $connect and $disconnect are the reserved routes in WebSocket APIs, which are automatically called by API Gateway whenever a client connects or disconnects from the WebSocket. By implementing these routes in the backend service, the developer can track and manage the client status, including identifying and removing the client when needed.
  2. catcatpunch 👍 10
    C => https://docs.aws.amazon.com/ko_kr/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html E => https://docs.aws.amazon.com/ko_kr/apigateway/latest/developerguide/apigateway-websocket-api-route-keys-connect-disconnect.html
  3. Phongsanth 👍 4
    Option C and E is my preferable choice. why do we have to use option D in case we apply $connect and $disconnect already in option E ? https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-route-keys-connect-disconnect.html
  4. loctong 👍 4
    Implementing a callback URL allows the backend service to initiate disconnection from the WebSocket connection.
  5. love777 👍 3
    D. Tracking Client Status: To identify and manage clients that connect and disconnect from the WebSocket connection, you need a way to persist this information. Amazon ElastiCache is a managed in-memory caching service that can be used to store this kind of data. By adding code to your backend service to track client status in ElastiCache, you can keep a record of client connections and disconnections. E. connectanddisconnect Routes: In API Gateway WebSocket APIs, the connectanddisconnect routes are special routes that are automatically triggered when a client connects and disconnects from the WebSocket connection. By implementing these routes in your backend service, you can capture the client information and update the client status in the ElastiCache, thus achieving the requirement of identifying clients and managing their connections.
Show 25 more comments
  1. SerialiDr 👍 2
    When a client connects to your WebSocket API, the $connect route is invoked, and when they disconnect, the $disconnect route is invoked. You can use these routes to track the state of each client. By maintaining a record of each client's connections and disconnections, possibly in a database or an in-memory data store like Amazon ElastiCache, you can identify clients that frequently connect and disconnect. Hence, the combination of changes that should be made to the application to meet these requirements includes: Implement $connect and $disconnect routes in the backend service (Option E). Add code to track the client status in Amazon ElastiCache in the backend service (Option D).
  2. Ashwinvdm22 👍 2
    C: https://docs.aws.amazon.com/ko_kr/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html D: You need a way to track which user is continuously reconnecting. That is why option D is so important because without it you will just be disconnecting every user that tries to connect cause then how will you know which user is the "problem" user. Note that you don't need the $disconnect endpoint to disconnect a client if you use option C. So CD is the only combination to solve the problem.
  3. Balliache520505 👍 2
    I go with C and E. https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-route-keys-connect-disconnect.html https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html
  4. robotgeek 👍 2
    You guys need to stop pasting ChatGPT answers and specially upvoting them without any reference link
  5. tsangckl 👍 2
    This appear at 17 Jun exam
  6. sumanshu 👍 1
    C. Use the callback URL to disconnect the client from the backend service This is essential for removing the client. Without it, the backend has no way to forcibly disconnect a problematic client. ✅ Must-have. D. Add code to track the client status in Amazon ElastiCache in the backend service Tracking client connection/disconnection behavior is critical to identifying problematic clients. ElastiCache is a highly suitable tool for storing connection data efficiently. ✅ Must-have. E. Implement $connect and $disconnect routes in the backend service While these routes are necessary for detecting client connections and disconnections, this could be seen as implicit in the implementation of D (since tracking client status assumes these routes are already used). ⚠️ Optional, depending on how the question is interpreted.
  7. SerialiDr 👍 1
    C. Use the callback URL to disconnect the client from the backend service: The callback URL can be used to send messages to connected clients or to disconnect them from the WebSocket connection. This approach allows the backend service to programmatically disconnect a client, which is useful for managing clients that frequently connect and disconnect. D. Add code to track the client status in Amazon ElastiCache in the backend service: Implementing client status tracking in the backend service, possibly using a fast, in-memory data store like Amazon ElastiCache, allows the application to monitor and record the behavior of each client. This can be used to identify clients with frequent connect/disconnect patterns.
  8. Saurabh04 👍 1
    Option DE: Implement $connect and $disconnect Routes: Add $connect and $disconnect routes to your WebSocket API. These routes handle client connections and disconnections. When a client connects ($connect), a Lambda function can add the connection ID to a data store (e.g., DynamoDB). When a client disconnects ($disconnect), another Lambda function can remove the connection ID from the data store. Track Client Status: Use Amazon ElastiCache (e.g., Redis) to track client status. Store relevant information (e.g., client IDs, connection timestamps) in ElastiCache. This allows you to identify clients that connect and disconnect
  9. sumanshu 👍 1
    A) Eliminated - Switching to HTTP APIs would eliminate the WebSocket capability entirely, B) Eliminated - REST APIs are also unsuitable for WebSocket connections, as they are designed for request-response interactions rather than persistent, real-time communication. Both C&E and D&E - seems correct C) - API Gateway provides a callback URL that your backend service can use to invoke the POST /connections/{connectionId} API with the disconnect command. D) E) Correct - The $connect route triggers when a client establishes a WebSocket connection. The $disconnect route triggers when a client disconnects from the WebSocket
  10. sumanshu 👍 1
    The two requirements in the question are: Identify a client that keeps connecting and disconnecting: This requires tracking client connections and disconnections over time. To achieve this, the backend needs a mechanism to log or store connection events for each client, which can then be analyzed to identify repeated connection patterns. Remove the client: Once the client is identified as problematic (e.g., frequent connects/disconnects), the backend needs to remove the client. This is achieved using the WebSocket callback URL to explicitly disconnect the client.
  11. Wardove 👍 1
    Although - option D is also correct, I would choose C and E 1) what we know 100% - we can disconnect uses using Callback url reference: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api.html 2) we definitely need to implement $connect and $disconnect routes (to identify during runtime) 3) we cannot technically track a user spamming connections if we don't pass this info logically to each invocation - and technically without persistence this is a mission impossible
  12. 41eb566 👍 1
    E. Implement $connect and $disconnect routes in the backend service. By implementing $connect and $disconnect routes, the backend service can capture when clients connect and disconnect from the WebSocket connection. This allows the application to track client status effectively. D. Add code to track the client status in Amazon ElastiCache in the backend service.
  13. tomchandler077 👍 1
    Option D ---> CORRECT Because, tracking the client's connection status using ElastiCache could help in identifying clients with erratic connection patterns and managing stateful information in a distributed environment, which is useful for WebSocket applications. Also Option E CORRECT. These routes handle connection and disconnection events.
  14. maurice2005 👍 1
    Your backend service can use the following WebSocket connection HTTP requests to send a callback message to a connected client, get connection information, or disconnect the client https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html
  15. KarBiswa 👍 1
    C option - Supports https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html E option supports - https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-route-keys-connect-disconnect.html
  16. sumanshu 👍 1
    D is critical for tracking client activity. E is required to capture connection and disconnection events. C provides the functionality to disconnect a client once identified. Thus, the correct combination is C, D, and E.
  17. a_win 👍 1
    D. Add code to track the client status in Amazon ElastiCache in the backend service. E. Implement $connect and $disconnect routes in the backend service.
  18. akmv2 👍 1
    How is D viable when the question doesn't mention Elasticache? You're making an assumption that adding a service/configuration is what's being asked
  19. LR2023 👍 1
    https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html
  20. 9d8dd9c 👍 1
    What about "the ability to remove the client"? for that it needs to use the callback function
  21. dbplearn 👍 1
    CE - Elasticache only stores data. It doesn't identify or remove clients
  22. sumanshu 👍 1
    C) Callback URL allows you to explicitly disconnect clients.
  23. mooncake1 👍 1
    Can't believe DE is 50%.. this q is not even hard
  24. mooncake1 👍 1
    DE does not make the developer disconnect
  25. frangesk 👍 1
    Do you remember the answers?

Reader comments & corrections

No reader corrections yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Practice All DVA-C02 Questions

Access 100 questions with complete answers and detailed explanations.

View Full DVA-C02 Practice Test →

← Back to DVA-C02 Study Guide