AWS recently introduced a new enhancement with direct message publishing over WebSocket connections for AWS AppSync Events, a fully-managed serverless WebSocket API service.
Earlier, the company released AWS AppSync Events, which allows developers to easily broadcast real-time event data to a few or millions of subscribers using secure and performant Serverless WebSocket APIs.
Darryl Ruggles, a cloud solutions architect and AWS Community Builder, tweeted on X:
Appsync Events came out a few months ago as a managed/serverless WebSocket API. There are other approaches to using WebSockets on AWS, but this works well for many cases. Now, support has been added for publishing messages directly over WebSocket connections.
Brice Pellé, a principal product manager at AWS, wrote in an announcement blog post:
This update allows developers to use a single WebSocket connection for both publishing and receiving events, streamlining the development of real-time features and reducing implementation complexity.
Developers gain flexibility by choosing between HTTP endpoints for backend publishing and WebSocket for web and mobile client applications. This enhancement will enable developers to build more responsive and engaging real-time applications, such as collaborative tools and live dashboards.
Developers can immediately test the new WebSocket publishing feature through the AppSync console’s Pub/Sub Editor. Selecting “WebSocket” as the publishing method triggers a publish_success message upon successful transmission.
(Source: AWS Front-End Web & Mobile blog post)
AppSync introduces a new “publish” WebSocket operation. After establishing a WebSocket connection, clients can publish events to configured channel namespaces. The message format requires an id, channel, an array of events (up to five), and authorization headers. Each event within the array must be a valid JSON string.
AWS also offers tools for infrastructure management to further streamline the development process. The AWS Cloud Development Kit (CDK) is an infrastructure-as-code framework that simplifies the configuration and deployment of AppSync Event APIs, including channel namespaces and API keys. The CDK consists of the L2 constructs that provide a higher-level abstraction, making it easier for developers to define AppSync Event APIs and their associated channel namespaces using familiar programming languages.
Yoseph Radding, a software engineer, posted on Bluesky:
That’s essentially how AWS CDK works. They define all of these high order constructs (called L2 constructs) the provide great out of the box abstractions. Like the Lambda constructs will create the versions, functions, and IAM roles.
Lastly, publishing over WebSocket is available in all regions where AppSync is supported. The client limit is 25 requests per second per connection. The HTTP endpoint can still be used for higher rates.