Serverless Backend with AWS Lambda & API Gateway · Ders

Gerçek Zamanlı İletişim için WebSocket API'leri

API Gateway WebSocket API'leriyle çift yönlü, gerçek zamanlı bağlantılar oluşturun. Bağlanma, bağlantı kesme ve mesaj rotalarını ve verileri istemcilere nasıl geri göndereceğinizi öğrenin.

4. ders / 413 adım

Gerçek Zamanlı İletişim için WebSocket API'leri, CoddyKit'te ücretsiz bir Serverless Backend with AWS Lambda & API Gateway dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Serverless Backend with AWS Lambda & API Gateway öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Serverless Backend with AWS Lambda & API Gateway kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Why WebSockets?

REST APIs are request/response — the server cannot push. For chat, live dashboards, or notifications you need a persistent two-way channel. API Gateway WebSocket APIs provide exactly that.

The Three Built-in Routes

A WebSocket API has special routes:

  • $connect when a client connects
  • $disconnect when it leaves
  • $default for unmatched messages

Route Selection Expression

Custom routes are chosen by a route selection expression, usually a field in the incoming JSON such as $request.body.action.

{
  "action": "sendMessage",
  "data": "hello"
}

Handling $connect

The $connect handler receives a unique connectionId. Store it (e.g. in DynamoDB) so you can message that client later.

exports.handler = async (event) => {
  const id = event.requestContext.connectionId;
  await save(id);
  return { statusCode: 200 };
};

Handling $disconnect

On disconnect, remove the stored connectionId so you do not try to message a dead client.

exports.handler = async (event) => {
  await remove(event.requestContext.connectionId);
  return { statusCode: 200 };
};

Pushing Messages to a Client

To send data back, call the management API with the target connectionId.

const api = new ApiGatewayManagementApi({ endpoint });
await api.postToConnection({
  ConnectionId: id,
  Data: JSON.stringify({ msg: "hi" })
});

Broadcasting to Many Clients

To broadcast, loop over all stored connectionIds and post to each. Remove any that return a 410 Gone status — those clients have disconnected.

Authorizing Connections

Attach a Lambda authorizer to the $connect route to validate a token before the connection is accepted, rejecting unauthorized clients up front.

Connection Lifetime and Limits

WebSocket connections last up to 2 hours, with a 10-minute idle timeout. Clients should reconnect when dropped, and you should handle stale connectionIds gracefully.

Pricing Model

You pay for messages transferred and for connection-minutes, not for idle request count. This makes WebSocket APIs cost-effective for bursty real-time traffic.

When to Use WebSockets

Reach for WebSocket APIs when you need:

  • Live chat or collaboration
  • Real-time dashboards
  • Server-initiated notifications

For simple request/response, stick with REST or HTTP APIs.

Quick Check

Test your WebSocket API knowledge.

Recap

You learned real-time APIs:

  • WebSocket APIs add two-way communication
  • $connect, $disconnect, $default plus custom routes
  • Store connectionIds and push via postToConnection
  • Authorize on $connect; handle stale connections
Başlamak ücretsiz

Yapay zeka eğitmeniyle Serverless Backend with AWS Lambda & API Gateway öğren — ücretsiz

Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.

Kurslar
12
Dersler
48

Sıkça Sorulan Sorular

“Gerçek Zamanlı İletişim için WebSocket API'leri” dersi ücretsiz mi?

Evet — “Gerçek Zamanlı İletişim için WebSocket API'leri” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Serverless Backend with AWS Lambda & API Gateway kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Serverless Backend with AWS Lambda & API Gateway kursu toplamda 4 dersten oluşur.

“Gerçek Zamanlı İletişim için WebSocket API'leri” dersinde ne öğreneceğim?

API Gateway WebSocket API'leriyle çift yönlü, gerçek zamanlı bağlantılar oluşturun. Bağlanma, bağlantı kesme ve mesaj rotalarını ve verileri istemcilere nasıl geri göndereceğinizi öğrenin. Serverless Backend with AWS Lambda & API Gateway ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Serverless Backend with AWS Lambda & API Gateway öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Serverless Backend with AWS Lambda & API Gateway, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“Gerçek Zamanlı İletişim için WebSocket API'leri” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Serverless Backend with AWS Lambda & API Gateway dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Serverless Backend with AWS Lambda & API Gateway dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Önbellekleme ve Trafik Sınırlama
  2. İstek/Yanıt Dönüşümleri
  3. Özel Etki Alanı Adları ve Kenar Optimizasyonu
  4. Gerçek Zamanlı İletişim için WebSocket API'leri
← Serverless Backend with AWS Lambda & API Gateway Sayfasına Dön