RealTime Servers & JavaScript SDK: AWS Answered Me!

Version 2 or Version 3?

Alexandre Bruffa
5 min readFeb 13, 2024

Weeks ago, I showed how a real-time multiplayer game can integrate AI components by connecting a GameLift Realtime server and Bedrock, Amazon’s new generative AI service. I recommend you check out my previous post to know step-by-step how to do it:

Hey! I made a video summarizing this post; check it out!

Context

This is the general architecture I used to integrate AI components into a real-time multiplayer game built with Amazon GameLift:

Let’s focus on the ⚡ part: To connect my Realtime server and Bedrock through a Lambda function, I added code to my Realtime script to assume the service role and invoke the Lambda function, as described in the GameLift documentation. Realtime servers use Node.js and JavaScript, so I used the AWS SDK for JavaScript.

🚨 For some reason, I could not use the AWS SDK for JavaScript version 3; it made my game server crash when starting. In the Events section, I figured out that an error was raised indicating that the game server was unhealthy and forcibly terminated:

When I used the AWS SDK for JavaScript version 2, everything worked like a charm. At this point, I wondered why I could not make it with version 3. Did I miss some requirements in the AWS documentation? Let’s delve into it.

JavaScript SDK Version 2 vs. Version 3

Working with version AWS SDK for JavaScript version 3 is convenient, and I will explain why. First, the AWS SDK for JavaScript version 2 is almost deprecated (maintenance mode), and the documentation is sometimes hard to find. As a developer, I prefer to work with up-to-date tools.

Then, remember that the AWS SDK for JavaScript is not installed on Realtime servers, so you have to install it locally, zip it along with your Realtime script, and upload it to GameLift. The main evolution from version 2 to version 3 is the SDK package’s modularity. With version 3, you can install and import only the packages you need instead of installing and importing the whole SDK into your code.

For the previous implementation, wrapping the whole SDK version 2 brought me another issue: the zip file was too large and could not be uploaded directly to GameLift. A workaround was uploading the file to an S3 bucket and creating an additional role, adding more complexity to the implementation.

Working with version 3 would have avoided those issues.

The Solution

The GameLift documentation shows no indications about the compatibility between Realtime servers and the AWS SDK for JavaScript version 3. However, in the AWS SDK for JavaScript v3 documentation, I found this requirement I missed the first time:

v3.201.0 and higher requires Node.js >= 14.
v3.46.0 to v3.200.0 requires Node.js >= 12.
Earlier versions require Node.js >= 10.

Realtime servers use Node.js, but which version of Node.js? No clue about it in the whole GameLift documentation, so let’s find out! In my Realtime script, I added code to print the Node.js version of the Realtime server into the logs:

Then, I read the game session logs, as I described in my previous post. Surprise! The Realtime servers are running an old version of Node.js: 10.15.2.

OK, that could be a problem! The actual version of the AWS SDK for JavaScript (v3.494.0) is not compatible with this version of Node.js. So, in my local environment, I installed the STS and Lambda packages with an old version that matches the Node.js requirements: v3.40.0:

npm install @aws-sdk/client-sts@v3.40.0
npm install @aws-sdk/client-lambda@v3.40.0

Then, re-wrap, re-upload to GameLift (without size issue!), re-create a fleet, and… it works! The game server and game sessions are running correctly.

Me when I found the solution

GameLift Team’s Answer

While I was stuck with this problem, I contacted the GameLift team, and they answered me the following:

Currently, GameLift does not support JavaScript v3 for Realtime Servers. We are happy to take this as an enhancement request and add it to our backlog. However, at this point, we cannot provide any timelines for the availability of this feature.

This makes sense! The AWS SDK for JavaScript version 3 does not offer full support, so the GameLift team recommends not using it.

Conclusion

Although I showed how to make it work with version 3, the GameLift team highly recommends using AWS SDK for JavaScript version 2. So, to access AWS resources from your Realtime server, you can use AWS SDK for JavaScript version 2 (recommended) or version 3 < v3.46.0 (at your own risk).

As an addendum to my previous article, you can find below the Realtime script I used in both versions:

A very big thanks to the GameLift team, who gave me a precise answer to my very technical question, and Chris Blackwell for his help and the guidance he’s always providing me regarding game services.

If you have any feedback or questions, feel free to reach out to me on my social networks:

🎬 YouTube Ⓜ️ Medium 🌐 Website

See you in the next post!

--

--

Alexandre Bruffa

I write cool stuff about Unity3D and AWS ★ AWS Community Builder ★ AWS certified ★ https://alexandrebruffa.com ★ Support me at https://ko-fi.com/alexandrebruffa