The purpose of this script is to help you deploy a game server update for Amazon GameLift hosting and then transition player traffic to game sessions running on the new game server. The mechanics of the script rely on the use of an Alias to designate a Fleet resource. With this script, you upload the game server update as a new Build resource and deploy it to a new Fleet resource. The script then updates the Alias assignment from the current Fleet to the new Fleet, once the new Fleet is ready to accept player traffic. At that point, players are directed to join game sessions that use the new version of the game server.
- Install AWS SDK for Python: https://aws.amazon.com/sdk-for-python/
- Install python packages for unit testing:
pip install pytest
pip install mock
pip install pytest-mock
This script offers a sample for uploading game server updates in a production environment. As your game hosting architecture matures to encompass multiple Fleets and AWS Regions, you'll need to customize the script to fit your deployment needs.
Keep in mind the following limitations, including best practices that the script doesn't currently handle:
- The script requires that your game uses Aliases to designate the destination of your game sessions, either in your GameSessionQueue or in your game's call to CreateGameSession.
- The script only supports game server uploads from your own S3 Bucket.
- You must input the specific resources you want to update. As a customization, you could use tags to list and find specific resources to replace in a more automated approach.
- When replacing an existing Fleet with a new Fleet, be sure that the new Fleet's capacity matches the old Fleet to handle player traffic when redirected. This can be done by modifying the script to call UpdateFleetCapacity, applying a scaling policy with PutScalingPolicy, or both. This should be done after the Fleet is ACTIVE and before updating the Alias.
- The script does not have features like error detection, resuming execution, or rollback options.
Name | Short Syntax | Description |
---|---|---|
--region | -r | The AWS Region the Fleet and Alias resources are located in. |
--fleet-id | -f | The FleetId of the existing Fleet being replaced. |
--alias-id | -a | The AliasId of the existing Alias being updated to direct traffic to the new Fleet. |
--build-json | -bj | A json file detailing the Build resource to be created. |
--fleet-json | -fj | A json file detailing the Fleet resource to be created. |
- Find the existing Fleet to replace:
aws gamelift describe-fleet-attributes --region <region>
to find the FleetId.- Learn more about DescribeFleetAttributes here
- Find the existing Alias to update and direct traffic to the new Fleet:
aws gamelift list-aliases --region <region>
to find the AliasId.- Learn more about ListAliases here
- Create a json skeleton for Build resource:
aws gamelift create-build --generate-cli-skeleton > new_build.json
- Create a json skeleton for Fleet resource:
aws gamelift create-fleet --generate-cli-skeleton > new_fleet.json
- Fill in Build and Fleet attributes in those new json files. Ideally this only needs to be done once and future updates will have minimal attributes to change on each revision.
- Execute the script:
python3 ./deployment.py -r us-west-2 \
--fleet-id fleet-12345678-1234-1234-1234-12345678 \
--alias-id alias-12345678-1234-1234-1234-12345678 \
--build_json new_build.json \
--fleet_json new_fleet.json
The script takes the following actions:
- Validate that the input Fleet and Alias exist with
describe-fleet-attributes
/describe-alias
. - Call
create-build
based on the input Build json file to create the new Build. - Loop calling
describe-build
until the new Build is in state READY. - Call
create-fleet
based on the input Fleet json file to create the new Fleet. - Loop calling
describe-fleet-attributes
until the new Fleet state is ACTIVE. - Loop calling
describe-fleet-location-attributes
until all new Fleet Locations are ACTIVE. - Call
update-alias
to update the Alias with the new Fleet and send player traffic to hardware running the new game server. - Loop calling
describe-game-sessions
on the old Fleet until there are none remaining. - Call
delete-fleet
on the old Fleet to cleanup the old game server version when it is no longer in use.
Unit tests are written using pytest, simply run from the parent directory:
pytest