1

当我在 AWS gamelift 中创建车队时,它返回此错误:

SERVER_PROCESS_TERMINATED_UNHEALTHY

Server process is unable to start. This may be due to a problem with either the Realtime script or the runtime configuration launch path., launchPath(/local/NodeJS/bin/node), arguments(-- /local/game/src/gamelift.js --script ../../../local/game/etag-658d8bb9e54727eedb83a2261100c2aa/realTimeServerScript --devargs "nothing"), instanceId(i-024de628bc4c774e7), publicIP(3.120.111.238), gameSessionId(none)

,一分钟后服务器(舰队)激活,但我没有在列表中的活动服务器。

将此代码用于 Lambda 测试:

exports.handler = async (event) => {
    // TODO implement
    const response = {
        statusCode: 200,
        body: JSON.stringify('Hello from Lambda!'),
    };
    return response;
};

const {"v4":uuidv4} = require('uuid');
const AWS = require('aws-sdk');
const GameLift = new AWS.GameLift({region: 'ap-south-1'});

const MegaFrogRaceFleetID = "fleet-3b3286f6-e1da-4df3-a179-0cef952980da";

exports.handler = async (event, context) => {
    let response;
    let gameSessions;

    // find any sessions that have available players
    await GameLift.searchGameSessions({
        FleetId: MegaFrogRaceFleetID,
        FilterExpression: "hasAvailablePlayerSessions=true"
    }).promise().then(data => {
        gameSessions = data.GameSessions;
    }).catch(err => {
        response = err;
    });

    // if the response object has any value at any point before the end of
    // the function that indicates a failure condition so return the response
    if(response != null) 
    {
        return response;
    }

    // if there are no sessions, then we need to create a game session
    let selectedGameSession;
    if(gameSessions.length == 0)
    {
        console.log("No game session detected, creating a new one");
        await GameLift.createGameSession({
            MaximumPlayerSessionCount: 2,   // only two players allowed per game
            FleetId: MegaFrogRaceFleetID
        }).promise().then(data => {
            selectedGameSession = data.GameSession;
        }).catch(err => {
           response = err; 
        });

        if(response != null)
        {
            return response;
        }
    }
    else
    {
        // we grab the first session we find and join it
        selectedGameSession = gameSessions[0];
        console.log("Game session exists, will join session ", selectedGameSession.GameSessionId);
    }
    
    // there isn't a logical way selectedGameSession could be null at this point
    // but it's worth checking for in case other logic is added
    if(selectedGameSession != null) 
    {
        // now we have a game session one way or the other, create a session for this player
        await GameLift.createPlayerSession({
            GameSessionId : selectedGameSession.GameSessionId ,
            PlayerId: uuidV4 //context.awsRequestId
        }).promise().then(data => {
            console.log("Created player session ID: ", data.PlayerSession.PlayerSessionId);
            response = data.PlayerSession;
        }).catch(err => {
           response = err; 
        });

    }
    else
    {
        response = {
          statusCode: 500,
          body: JSON.stringify({
              message: "Unable to find game session, check GameLift API status"
          })
        };
    }

    return response;
};

我收到此错误:

Response:
{
  "message": "Fleet fleet-3b3286f6-e1da-4df3-a179-0cef952980da not found.",
  "code": "NotFoundException",
  "time": "2020-10-09T20:26:02.626Z",
  "requestId": "e7b940b4-2476-4e15-b1df-7fe16e4fb551",
  "statusCode": 400,
  "retryable": false,
  "retryDelay": 13.439762405533017
}

Request ID:
"bc1e82a3-f7b4-44c7-abdf-ba78eef2ccb3"

Function logs:
START RequestId: bc1e82a3-f7b4-44c7-abdf-ba78eef2ccb3 Version: $LATEST
END RequestId: bc1e82a3-f7b4-44c7-abdf-ba78eef2ccb3
REPORT RequestId: bc1e82a3-f7b4-44c7-abdf-ba78eef2ccb3  Duration: 1338.13 ms    Billed Duration: 1400 ms    Memory Size: 128 MB Max Memory Used: 87 MB  Init Duration: 420.14 ms    

有关更多参考,我遵循了本教程的第 1 部分和第 2 部分: https ://www.youtube.com/watch?v=WaAZyqgkXDY&t=315s

4

0 回答 0