Lesson 35 - Get Compute Auth Token Working

This commit is contained in:
Norman Lansing
2026-02-28 12:32:28 -05:00
parent 1d477ee42a
commit 4fde462bce
7743 changed files with 1397833 additions and 18 deletions

View File

@@ -0,0 +1,162 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "CoreMinimal.h"
namespace Menu
{
namespace DeploymentServer
{
static const auto kSingleRegionFleet = NSLOCTEXT("SGameLiftDeploymentMenu", "SingleRegionFleet_Scenario", "Single-region fleet");
static const auto kSpotFleets = NSLOCTEXT("SGameLiftDeploymentMenu", "SpotFleets_Scenario", "Spot fleet");
static const auto kFlexMatch = NSLOCTEXT("SGameLiftDeploymentMenu", "FlexMath_Scenario", "FlexMatch fleet");
static const auto kContainersSingleRegionFleet = NSLOCTEXT("SGameLiftDeploymentMenu", "ContainersSingleRegionFleet_Scenario", "Single-region Containers Fleet");
static const auto kContainersFlexMatch = NSLOCTEXT("SGameLiftDeploymentMenu", "ContainersFlexMath_Scenario", "FlexMatch Containers Fleet");
static const auto kCustom = NSLOCTEXT("SGameLiftDeploymentMenu", "Custom_Scenario", "Custom");
static const auto kSingleRegionFleetTooltip = NSLOCTEXT("SGameLiftDeploymentMenu", "SingleRegionFleet_ToolTip",
"Use this scenario to deploy a minimal managed EC2 fleet for your game server. This scenario also sets up player authentication for your game and creates a backend service for game clients to start and join game sessions.");
static const auto kSpotFleetsTooltip = NSLOCTEXT("SGameLiftDeploymentMenu", "SpotFleets_ToolTip",
"Forms matches by using Amazon GameLift queues and a custom matchmaker and configures three fleets.");
static const auto kFlexMatchTooltip = NSLOCTEXT("SGameLiftDeploymentMenu", "FlexMath_ToolTip",
"Use this scenario to deploy a fully configured set of managed EC2 fleets with matchmaking. This scenario also sets up a queue to manage game session placement across Spot and On-Demand fleets, handles player authentication and creates a backend service for game clients to request matchmaking and join matches.");
static const auto kContainersSingleRegionFleetTooltip = NSLOCTEXT("SGameLiftDeploymentMenu", "ContainersSingleRegionFleet_ToolTip",
"Creates a game backend service with a single Amazon GameLift Containers fleet.");
static const auto kContainersFlexMatchTooltip = NSLOCTEXT("SGameLiftDeploymentMenu", "ContainersFlexMath_ToolTip",
"Uses FlexMatch, a managed matchmaking service, to match game players together across Amazon GameLift Containers fleets.");
static const auto kCustomTooltip = NSLOCTEXT("SGameLiftDeploymentMenu", "Custom_ToolTip",
"This is a custom user scenario.");
static const auto kSingleRegionFleetFolder = TEXT("scenario1_single_fleet");
static const auto kSpotFleetsFolder = TEXT("scenario2_spot_fleets");
static const auto kFlexMatchFolder = TEXT("scenario3_flexmatch");
static const auto kContainersSingleRegionFleetFolder = TEXT("scenario3_containers_single_fleet");
static const auto kContainersFlexMatchFolder = TEXT("scenario4_containers_flexmatch");
static const auto kCurrentScenarioFolder = TEXT("scenario_current");
static const auto kCustomScenarioFolder = TEXT("scenario_custom");
}
} // namespace Menu
namespace Bootstrap
{
namespace Logs
{
static const auto kLogReceived = TEXT("Native log message: ");
static const auto kReceiveBucketNameCallback = TEXT("AWSBootstrapProfile: Received a bucket name:");
static const auto kBootstrapStarted = TEXT("AWSBootstrapProfile: Bootstrapping.........");
static const auto kBootstrapCompleted = TEXT("AWSBootstrapProfile: Bootstrapped.");
static const auto kBootstrapFailedCreateAccount = TEXT("AWSBootstrapProfile: Unable to create AWS credentials profile with an error: ");
static const auto kBootstrapFailedBootstrap = TEXT("AWSBootstrapProfile:Unable to bootstrap account with an error: ");
static const auto kBootstrapFailedAccountNotValid = TEXT("AWSBootstrapProfile: Account does not contain valid data.");
}
} // namespace Bootstrap
namespace Deploy
{
static const auto kMaxGameNameWithPrefixLength = 30;
namespace Logs
{
static const auto kLogReceived = TEXT("Native log message:");
static const auto kReceiveReplacementIdCallback = TEXT("AWSScenariosDeployer: Received a function replacement id:");
static const auto kReceiveClientConfigPathCallback = TEXT("AWSScenariosDeployer: Received a client config path:");
static const auto kRunAwsScenario = TEXT("AWSScenariosDeployer: Run scenario:");
static const auto kRunCustomScenario = TEXT("AWSScenariosDeployer: Run custom scenario path:");
static const auto kAccountInstanceIsNull = TEXT("AWSScenariosDeployer: Invalid account instance, bootstrap is required.");
static const auto kCreateAndSetFunctionsReplacementIdFailed = TEXT("GameLiftAccountCreateAndSetFunctionsReplacementId failed with error:");
static const auto kGetMainFunctionsReplacementIdFailed = TEXT("kGetMainFunctionsReplacementIdFailed failed with error:");
static const auto kCreateLaunchPathParameterFailed = TEXT("CreateLaunchPathParameter failed with error:");
static const auto kInvalidServerFilePath = TEXT("Game Server File Path has to be a subpath of Game Server Build Folder.");
static const auto kSaveFeatureInstanceTemplatesFailed = TEXT("GameLiftAccountSaveFeatureInstanceTemplates failed with error:");
static const auto kAccountUploadFunctionsFailed = TEXT("GameLiftAccountUploadFunctions failed with error:");
static const auto kUploadGameServerFailed = TEXT("GameLiftAccountUploadGameServer failed with error:");
static const auto kCreateOrUpdateMainStackFailed = TEXT("GameLiftAccountCreateOrUpdateMainStack failed with error:");
static const auto kDeployApiGatewayStageFailed = TEXT("GameLiftAccountDeployApiGatewayStage failed with error:");
static const auto kDeploymentStackStatusFailed = TEXT("Deployment stack status failed with error:");
static const auto kDeploymentHasBeenStopped = TEXT("Deployment has been cancelled by user.");
static const auto kDeploymentStackStatus = TEXT("Deployment stack status is:");
static const auto kDeploymentStop = TEXT("Stop deployment...");
}
namespace Errors
{
static const auto kAccountIsInvalidText = NSLOCTEXT("SGameLiftDeploymentMenu", "AccountIsInvalidText", "This account is invalid. Please check your credentials.");
static const auto kGameNameIsTooLongText = NSLOCTEXT("SGameLiftDeploymentMenu", "GameNameIsTooLongText", "Game name is too long. Game name must have 1-16 characters.");
static const auto kNoStacksToStopDeployment = NSLOCTEXT("SGameLiftDeploymentMenu", "kNoStacksToStopDeployment", "Currently no active stacks are available.");
static const auto kUnableToStopDeployment = NSLOCTEXT("SGameLiftDeploymentMenu", "kUnableToStopDeployment", "Currently it is not possible to stop deployment.");
}
} // namespace Deploy
namespace Account
{
namespace Logs
{
static const auto kLogReceived = TEXT("Native log message: ");
static const auto kUnableToBuildCredentials = TEXT("AwsAccountInstanceManager: Unable to build credentials.");
static const auto kUnableToBuildAccountInfo = TEXT("AwsAccountInstanceManager: Unable to build account info.");
static const auto kAccountIsNotCreated = TEXT("AwsAccountInstanceManager: Account is not created.");
static const auto kAccountIsInvalid = TEXT("AwsAccountInstanceManager: Account is invalid.");
}
} // namespace Account
namespace Credentials
{
namespace Logs
{
static const auto kLogReceived = TEXT("Native log message: ");
static const auto kUnableToGetAccountId = TEXT("AwsAccountCredentials: Unable to get account id with an error:");
}
} // namespace Credentials
namespace Aws
{
namespace Config
{
static const auto kUserPoolClientIdYamlName = "user_pool_client_id";
static const auto kApiGatewayEndpointYamlName = "identity_api_gateway_base_url";
}
namespace Status
{
static const auto kStackUndeployed = "UNDEPLOYED";
static const auto kStackUpdateComplete = "UPDATE_COMPLETE";
static const auto kStackCreateComplete = "CREATE_COMPLETE";
}
} // namespace Aws
namespace Process
{
static const auto kWaitForProcMs = 5000;
} // namespace Process
namespace Core
{
static const auto sGameLiftCoreName = TEXT("GameLiftCore");
static const auto sGameLiftPluginName = TEXT("GameLiftPlugin");
namespace Logs
{
static const auto kStartupModule = TEXT("FGameLiftCoreModule StartupModule");
static const auto kShutdownModule = TEXT("FGameLiftCoreModule Shutting down");
static const auto kDllLoaded = TEXT("DLL loaded");
}
} // namespace Core
namespace Anywhere
{
static const auto kCustomLocationPrefix = TEXT("custom-location-unreal");
static const auto kAnywhereFleetDescription = TEXT("Deployed by the Amazon GameLift Plug-in for Unreal.");
static const auto kAnywhereFleetTagKey = TEXT("CreatedBy");
static const auto kAnywhereFleetTagValue = TEXT("AmazonGameLiftUnrealPlugin");
}

View File

@@ -0,0 +1,18 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GameLiftExports.generated.h"
UCLASS()
class GAMELIFTCORE_API UGameLiftExports : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable, Category = "GameLiftExports")
static FString GetGameLiftPluginName();
};

View File

@@ -0,0 +1,18 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
class IAWSAccountInstance
{
public:
virtual ~IAWSAccountInstance() = default;
virtual bool IsValid() const = 0;
virtual void* GetInstance() const = 0;
virtual FString GetBucketName() const = 0;
virtual const char* GetGameName() const = 0;
virtual const char* GetAccountId() const = 0;
virtual const char* GetBuildConfiguration() const = 0;
virtual FString GetLastErrorMessage() const = 0;
};

View File

@@ -0,0 +1,22 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "IAWSConfigFileProfile.h"
class FString;
class IAWSAccountInstance;
class IAWSBootstrapProfile
{
public:
virtual ~IAWSBootstrapProfile() = default;
virtual bool ConfigureAccount(const FString& ProfileName, TSharedRef<IAWSConfigFileProfile> ProfileReader, const FString& ExistingBucketName = "") = 0;
virtual bool Bootstrap(const FString& NewBucketName = "") = 0;
virtual FString GetLastError() const = 0;
virtual FString GetLastErrorMessage() const = 0;
virtual FString GetDefaultBucketName(const FString& ProfileName, TSharedRef<IAWSConfigFileProfile> ProfileReader) const = 0;
virtual IAWSAccountInstance* GetAccountInstance() = 0;
};

View File

@@ -0,0 +1,30 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "Containers/UnrealString.h"
#include "Containers/Array.h"
class IAWSConfigFileProfile
{
public:
virtual ~IAWSConfigFileProfile() = default;
virtual TArray<FString> GetProfileNames() const = 0;
virtual void CreateProfile(const FString& ProfileName) = 0;
virtual void RenameProfile(const FString& ProfileName, const FString& NewProfileName) = 0;
virtual FString GetAccessKey(const FString& ProfileName) const = 0;
virtual void SetAccessKey(const FString& ProfileName, const FString& accessKey) = 0;
virtual FString GetSecretAccessKey(const FString& ProfileName) const = 0;
virtual void SetSecretAccessKey(const FString& ProfileName, const FString& secretAccessKey) = 0;
virtual FString GetSessionToken(const FString& ProfileName) const = 0;
virtual void SetSessionToken(const FString& ProfileName, const FString& sessionToken) = 0;
virtual FString GetRegion(const FString& ProfileName) const = 0;
virtual void SetRegion(const FString& ProfileName, const FString& region) = 0;
virtual void Save() = 0;
};

View File

@@ -0,0 +1,62 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "IAWSAccountInstance.h"
enum class IAWSScenariosCategory : unsigned int
{
ManagedEC2 = 0,
Containers = 1
};
class IAWSScenariosDeployer
{
public:
virtual ~IAWSScenariosDeployer() = default;
virtual bool DeployManagedEC2Scenario(
const FText& Scenario,
IAWSAccountInstance* AccountInstance,
const FString& GameName,
const FString& BuildOperatingSystem,
const FString& BuildFolderPath,
const FString& BuildFilePath,
const FString& OutConfigFilePath,
const FString& ExtraServerResourcesPath,
bool EnableMetrics
) = 0;
virtual bool DeployCustomScenario(
const FString& CustomScenarioPath,
IAWSAccountInstance* AccountInstance,
const FString& GameName,
const FString& BuildOperatingSystem,
const FString& BuildFolderPath,
const FString& BuildFilePath,
const FString& OutConfigFilePath,
const FString& ExtraServerResourcesPath
) = 0;
virtual bool DeployContainerScenario(
const FText& Scenario,
IAWSAccountInstance* AccountInstance,
const FString& ContainerGroupDefinitionName,
const FString& ContainerImageName,
const FString& ContainerImageUri,
const FString& IntraContainerLaunchPath,
const FString& GameName, const FString& OutConfigFilePath,
const FText& ConnectionPortRange,
const FString& TotalVcpuLimit,
const FString& TotalMemoryLimit,
bool EnableMetrics
) = 0;
virtual bool StopDeployment(IAWSAccountInstance* AwsAccountInstance) = 0;
virtual FString GetLastCognitoClientId() const = 0;
virtual FString GetLastApiGatewayEndpoint() const = 0;
virtual FString GetLastError() const = 0;
virtual FString GetLastErrorMessage() const = 0;
virtual TArray<FText> GetScenarios(const IAWSScenariosCategory Category) const = 0;
virtual FText GetToolTip(const FText& ScenarioName, const IAWSScenariosCategory Category) const = 0;
};

View File

@@ -0,0 +1,72 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "Containers/UnrealString.h"
#include "Containers/Array.h"
struct GameLiftAnywhereResult
{
bool bIsSuccessful;
FString ErrorMessage;
};
struct GameLiftAnywhereCreateLocationResult : public GameLiftAnywhereResult
{
FString LocationName;
};
struct GameLiftAnywhereCreateFleetResult : public GameLiftAnywhereResult
{
FString FleetName;
FString FleetId;
};
struct GameLiftAnywhereAddFleetLocationResult : public GameLiftAnywhereResult
{
FString LocationName;
FString FleetId;
};
struct GameLiftAnywhereDescribeFleetsResult : public GameLiftAnywhereResult
{
struct FleetAttributes
{
FString FleetName;
FString FleetId;
};
TArray<FleetAttributes> Fleets;
};
struct GameLiftAnywhereRegisterComputeResult : public GameLiftAnywhereResult
{
FString ComputeName;
FString LinkedFleetId;
FString RegisteredIPAddress;
};
struct GameLiftAnywhereAuthTokenResult : public GameLiftAnywhereResult
{
FString AuthToken;
FDateTime ExpirationTime;
};
class IGameLiftAnywhereHandler
{
public:
virtual ~IGameLiftAnywhereHandler() = default;
virtual GameLiftAnywhereCreateLocationResult CreateCustomLocation(const FString& InRegion) = 0;
virtual GameLiftAnywhereCreateFleetResult CreateFleet(const FString& InFleetName, const FString& InCustomLocation) = 0;
virtual GameLiftAnywhereAddFleetLocationResult AddFleetLocation(const FString& InFleetId, const FString& InCustomLocation) = 0;
virtual GameLiftAnywhereDescribeFleetsResult DescribeAnywhereFleets() = 0;
virtual GameLiftAnywhereRegisterComputeResult RegisterCompute(const FString& InComputeName, const FString& InIPAddress, const FString& InFleetId, const FString& InCustomLocation) = 0;
virtual GameLiftAnywhereAuthTokenResult GenerateAuthToken(const FString& InFleetId, const FString& InComputeName) = 0;
};

View File

@@ -0,0 +1,88 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
struct GameLiftECRResult
{
bool bIsSuccessful;
FString ErrorMessage;
};
struct GameLiftContainersResult
{
bool bIsSuccessful;
FString ErrorMessage;
};
struct GameLiftECRCreateRepositoryResult : public GameLiftECRResult
{
FString RepositoryName;
FString RepoUri;
};
struct GameLiftDescribeCgdResult : public GameLiftContainersResult
{
FString CgdVersion;
FString CgdStatus;
};
struct GameLiftDescribeContainerFleetResult : public GameLiftContainersResult
{
FString FleetId;
FString FleetStatus;
FString FleetType;
FString InstanceType;
};
struct GameLiftContainersCreateCgdResult : public GameLiftContainersResult
{
FString CgdName;
};
struct GameLiftContainersListCgdsResult : public GameLiftContainersResult
{
struct CgdAttributes
{
FString CgdName;
};
TArray<CgdAttributes> Cgds;
};
struct GameLiftECRDescribeRepositoriesResult : public GameLiftECRResult
{
struct RepositoryAttributes
{
FString RepositoryName;
FString RepositoryUri;
};
TArray<RepositoryAttributes> Repos;
};
struct GameLiftECRListImagesResult : public GameLiftECRResult
{
struct ImageDetailAttributes
{
FString ImageDigest;
FString ImageTag;
};
TArray<ImageDetailAttributes> Images;
};
class IGameLiftContainersHandler
{
public:
virtual ~IGameLiftContainersHandler() = default;
virtual void SetupContainersDirectory(const FString BuildZipSource, const FString GameExecutable, const FString ContainersDestinationDirectory) = 0;
virtual GameLiftECRCreateRepositoryResult CreateRepository(const FString& InRepositoryName) = 0;
virtual GameLiftECRDescribeRepositoriesResult DescribeRepositories() = 0;
virtual GameLiftECRListImagesResult ListImages(const FString& InRepositoryName) = 0;
virtual GameLiftContainersListCgdsResult ListCgds() = 0;
virtual GameLiftDescribeCgdResult DescribeCgd(const FString& InCgdName) = 0;
virtual GameLiftDescribeContainerFleetResult DescribeContainerFleet(const FString& GameName) = 0;
};

View File

@@ -0,0 +1,57 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "IGameLiftCoreProc.h"
#include "IAWSScenariosDeployer.h"
#include "IAWSConfigFileProfile.h"
#include "IAWSBootstrapProfile.h"
#include "IGameLiftAnywhereHandler.h"
#include "IGameLiftContainersHandler.h"
#include "GameLiftCoreConstants.h"
#include "Templates/SharedPointer.h"
/**
* Interface for the ObjectBrowser module.
*/
class IGameLiftCoreModule : public IModuleInterface
{
public:
/**
* Singleton-like access to this module's interface. This is just for convenience!
* Beware of calling this during the shutdown phase, though. Your module might have been unloaded already.
*
* @return Returns singleton instance, loading the module on demand if needed
*/
static inline IGameLiftCoreModule& Get()
{
return FModuleManager::LoadModuleChecked<IGameLiftCoreModule>(Core::sGameLiftCoreName);
}
/**
* Checks to see if this module is loaded and ready. It is only valid to call Get() if IsAvailable() returns true.
*
* @return True if the module is loaded and ready to use
*/
static inline bool IsAvailable()
{
return FModuleManager::Get().IsModuleLoaded(Core::sGameLiftCoreName);
}
public:
virtual TSharedRef<IGameLiftCoreProc> MakeRunner() = 0;
virtual IAWSScenariosDeployer& GetScenarioDeployer() = 0;
virtual IAWSBootstrapProfile& GetProfileBootstrap() = 0;
virtual IGameLiftAnywhereHandler& GetGameLiftAnywhereHandler() = 0;
virtual IGameLiftContainersHandler& GetGameLiftContainersHandler() = 0;
virtual TSharedRef<IAWSConfigFileProfile> MakeAWSConfigFileProfile() = 0;
/**
* Virtual destructor
*/
virtual ~IGameLiftCoreModule() { }
};

View File

@@ -0,0 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
class IGameLiftCoreProc
{
public:
virtual ~IGameLiftCoreProc() = default;
virtual bool LaunchProcess(const FString& path, TArray<FString> arguments) = 0;
};