Giter Club home page Giter Club logo

aws-gamelift-tutorial's Introduction

AWS GameLift with Unreal Engine

Credits to Flopperam:

Link to Flopperam's Tutorial Playlist

This tutorial is more linear, meaning you are creating the entire project from scratch. Rather than continuing from the finished build in this repo.

Roadmap of the connection:

Roadmap

Installation:

Start up:

Guide to begin accessing the Test Project:

  • Right click the GameLiftTutorial.uproject and generate the Visual Studios project
  • Select Development Editor, Win64 and build the project
  • This time select Development Server, Win64 and build again
  • Launch the GameLiftTutorial.uproject (or rebuild the development editor)
  • On the top left, File -> Package Project -> Build Target -> GameLiftTutorialServer
  • Then package the project, File -> Package Project -> Win64 (can choose any build, just specify when uploading to AWS)

Uploading to AWS:

Packaging the game files to AWS and allowing AWS to launch a light-weight EC2 desktop with the server executable

  • Download VC_Redist x64

    • This allows the EC2 instance to run Visual Studio Code!
  • Navigate to WindowsServer inside the game folder, drag and drop the installation executable into the folder.

  • Create a install.bat file inside the folder and add these commands

    VC_redist.x64.exe /q
    Engine\Extras\Redist\en-us\UE4PrereqSetup_x64.exe /q
    
  • Open a terminal and use this command.

    aws gamelift upload-build --name GameLiftTutorial --build-version 1.0.0 --build-root $(FILE_PATH_TO_SERVER_FILES) --operating-system WINDOWS_2012 --region $(REGION_NAME)
    
    • Operating system is based on the build of the packaged Unreal Engine game, ex. Windows above.
    • $(REGION_NAME) - I have been using us-west-2

Creating the fleet, queue and matchmaking:

  • Navigate to the AWS GameLift dashboard Image
  • You will see that your packaged server is on AWS, but now we need to create the Fleet:
    • Name: $(NAME)
    • Fleet Type: Choose $(ON-DEMAND) for reserved resources for your server, or $(SPOT) for leftover resources (This is Cheaper!)
    • Build: $(GameLiftTutorial 1.00 ...)
    • Home Region: Ensure that this region is the same as what you used to upload earlier
    • Leave everything else as default
    • Launch Path: \game\GameLiftTutorial\Binaries\Win64\GameLiftTutorialServer.exe
      • Parameters: -port=7777
      • Concurrent Processes: 1
      • Don't forget the green check mark!
    • EC2 Port Range: 7777
      • Protocol: UDP
      • IP Address: 0.0.0.0/0
    • Click Submit! This will take a couple of minutes to create
  • Creating the Queue:
    • Choose any name
    • Down at the bottom, click add destination
    • Select the region, Fleet, and the name of the Fleet we just created
  • Creating the Matchmaking:
    • Navigate to "Create matchmaking rule set"
    • Use the first example for rule set
    • Click Validate, then Create.
    • Navigate to "Create matchmaking configuration"
      • Choose any name, leave everything as default
      • Request timeout: (Any number of seconds preffered, I had 60)
      • Rule set name: (Select the rule set created above)
    • Click Create!

Creating lambda functions:

Here we will create 11 different functions that we will connect together into a new API.

  • InvalidateTokens (GET)* -L
  • GetSignInResult (GET)
  • RetrieveNewTokens (POST)* -L
  • ValidateDuplicateEmail -L
  • StartMatchmaking (POST)* -L
  • PollMatchmaking (POST)* -L
  • TrackEvents -L
  • StopMatchmaking (POST)* -L
  • InitializePlayerData -L
  • ExchangeCodeForTokens (POST)
  • GetPlayerData (POST)* -L

All of the code for these functions will be in the "lambda" folder of this repo

Note: '-L' represents the need to create a layer before creating the function.

In these functions, you will find sections where you will need to input the identification from the next sections.

Setting up your Cognito user pool:

This is how we track users and enable the Google Sign In

  • Navigate: Manage User Pools -> Create User Pool -> $(NAME) -> Review Defaults -> Create Pool
  • Add an App Client
    • MAKE SURE TO UNCHECK "GENERATE CLIENT SECRET" <- If left checked, your lamdba functions will return "invalid client"
  • On the side bar, click on App Client
    • This is your Client Id that you will replace in your lambda code

Let's skip over to API Gateways:

This is creating our API call! We will need the lambda functions to complete our Cognito User Pool.

Note: We are only connecting 8/11 functions created above in our API.

  • Create API -> Rest API -> Default settings

  • Actions -> Create Resource -> $(NAME_OF_LAMBDA_FUNCTION) -> Create Resource

  • Click on the resource created -> Actions -> Create Method -> $(GET/POST) -&gt; Check "Use Lambda Proxy integration" -&gt; $(REGION) -> $(NAME_OF_LAMBDA_FUNCTION)

    • In the section, Creating Lambda Functions, you will find which functions will need $(GET/POST)
  • Complete the next 7 functions following the same steps!

  • Action -> Deploy API

  • Navigate to Stages on the left sidebar

Back to Cognito user pool:

  • Click on the "get" of the "GetSignInResult" and copy the "InvokeURL"
  • Navigating back to Cognito User Pool -> App Client Settings
  • Check Select All -> Paste the InvokeURL into the CallbackURLs
  • Check Authorization Code Grant -> Check all available scopes -> Save
  • Navigate to "Domain Name" -> Create a Domain
  • Back to App Client Settings
    • There should now be a Hosted UI that is availabe to click
    • Image
  • Navigate to Resource Servers
    • Create a new resource, whatever you named as the identifier is what you'll see on your App Client Settings
    • Add a scope! I named mine "access" and "gdsfwe"
  • Check the resource created above inside the App Client Setting

Enabling Google sign-on:

Note: You can check if this works by clicking on Hosted UI from App Client Setting. You should see an option for Google Sign In!

Finishing up Cognito user pool:

  • Navigate to Triggers
    • Pre Sign Up -> Select ValidateDuplicateEmail
    • Post Sign Up -> Select InitializePlayerData
  • Navigate back to API Gateways
  • Create an Authorizer
    • Select Cognito
    • $(NAME_OF_USER_POOL)
    • Token Source: 'Authorization'
  • ON ALL OF THE FUNCTIONS WITH A '*', you will need to complete the following
    • Select GET/POST -> Method Request
      • Authorization: $(NAME_OF_AUTHORIZER)
      • OAuth Scope: $(NAME_OF_API_FROM_COGNITO)
        • Ex. arnoc.api/access

Setting Up additional tables:

Setting up DynamoDB and Amazon SNS

  • Create 2 tables, "MatchmakingTickets" and "Players" with the Partition Key: Id (String)

    • For MatchmakingTickets, enable TTL
    • Note: Use these exact name, unless you want to change all instances in the Lambda Functions
  • Set up defaults of Simple Notification Service (SNS)

Final steps:

Setting up the connection from Game Engine to AWS Fleet Services and packing the final game!

  • Navigate to your game folder -> Content
  • Create a new folder named Urls
  • You will now create 4 text files with the following names:
    • ApiUrl
      • The InvokeURL where we deployed the API in API Gateway
    • CallbackUrl
      • This can be found in the App Settings of AWS Cognito
    • LoginUrl
      • This can be found through the Hosted UI from the App Settings of AWS Cognito. It is the URL of the Hosted UI
    • RegionCode
      • Region code for the region of AWS GameLift
    • Example of Text Files
  • Open up the Unreal Engine editor and package the game!
    • File -> Package Project -> Build Target -> GameLiftTutorial
    • File -> Package Project -> Win64

Done!

  • Be sure to go back into your lamdba functions and 'edit' the necessary functions!
  • (Optional): Setting up AWS CloudWatch for extra logs!
  • (Optional): Use Postman as a quick way to test your lambda functions/API calls
  • Note: You'll need to launch 2 instances at once for the matchmaking to work! WindowsNoEditor -> GameLiftTutorial.exe

Final notes:

How can we transition this example of a 3rd person multiplayer game for the capabilities of ARNOC_alpha?

  • Applying the steps from Google Oauth to CI Login:
    • Other than having to make an account with Google, we connected Google OAuth to AWS's Cognito page
    • However, we used a plugin called, "WebBrowserWidget", which allowed for the web browser aspect of this game. We were redirected to a login page where users were able to choose whether or not to use a Google Login.
      • This widget can be used to redirect users to the CI login!
  • Other plugins:
    • UMG
    • SlateCore
    • Http
    • Json
    • JsonUtilities

Next steps:

  • Upload the arnoc build, creating a fleet and queue!
  • Configuring a new matchmaking rule set that will allow for a non-team aspect
    • This was tried! But we need to edit the code for lambda or/and VS code
    • Why? The results that we are getting are not matching with Lambda functions, so it is stopping!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.