private InvokeAsync ( |
||
request | ||
return | Amazon.Lambda.Model.InvokeAsyncResponse |
public void UpdateRedis(bool serverTerminated = false) { var gameServerStatusData = new GameServerStatusData(); gameServerStatusData.taskArn = this.taskDataArnWithContainer; gameServerStatusData.currentPlayers = this.server.GetPlayerCount(); gameServerStatusData.maxPlayers = Server.maxPlayers; gameServerStatusData.publicIP = this.publicIP; gameServerStatusData.port = Server.port; gameServerStatusData.serverTerminated = serverTerminated; gameServerStatusData.gameSessionsHosted = Server.hostedGameSessions; var lambdaConfig = new AmazonLambdaConfig() { RegionEndpoint = this.regionEndpoint }; lambdaConfig.MaxErrorRetry = 0; //Don't do retries on failures var lambdaClient = new Amazon.Lambda.AmazonLambdaClient(lambdaConfig); // Option 1. If TCPListener is not ready yet, update as not ready if (!this.server.IsReady()) { Debug.Log("Updating as not ready yet to Redis"); gameServerStatusData.ready = false; gameServerStatusData.serverInUse = false; } // Option 2. If not full yet but, update our status as ready else if (this.server.IsReady() && this.server.GetPlayerCount() < Server.maxPlayers) { Debug.Log("Updating as ready to Redis"); gameServerStatusData.ready = true; gameServerStatusData.serverInUse = false; } // Option 3. If full, make sure the available key is deleted in Redis and update the full key else { Debug.Log("Updating as full to Redis"); gameServerStatusData.ready = true; gameServerStatusData.serverInUse = true; } // Call Lambda function to update status var request = new Amazon.Lambda.Model.InvokeRequest() { FunctionName = "FargateGameServersUpdateGameServerData", Payload = JsonConvert.SerializeObject(gameServerStatusData), InvocationType = InvocationType.Event }; // NOTE: We could catch response to validate it was successful and do something useful with that information lambdaClient.InvokeAsync(request); }
public async Task <LambdaSizeCalculationResultItem> RunTestAsync(LambdaInvocationRequest invocationRequest) { Console.WriteLine("Starting config fetch prior to test run"); var settings = await _client.GetFunctionConfigurationAsync(invocationRequest.FunctionName); var memory = settings.MemorySize; Console.WriteLine("Starting dry run"); await _client.InvokeAsync(await CreateLambdaRequest(invocationRequest)); Console.WriteLine("Starting test run # 1"); var response = await _client.InvokeAsync(await CreateLambdaRequest(invocationRequest)); Console.WriteLine("Starting test run # 2"); var response2 = await _client.InvokeAsync(await CreateLambdaRequest(invocationRequest)); if (response.StatusCode > 299 || response.StatusCode < 200) { throw new InvalidProgramException($"The Lambda which was invoked with the given payload returned with a status code not in the 200 series. The status code was '{response.StatusCode}'"); } if (response2.StatusCode > 299 || response2.StatusCode < 200) { throw new InvalidProgramException($"The Lambda which was invoked with the given payload returned with a status code not in the 200 series. The status code was '{response2.StatusCode}'"); } var log1 = response.LogResult; var item1 = ParseResultFromLog(log1, memory); var log2 = response2.LogResult; var item2 = ParseResultFromLog(log2, memory); var item = item2.Latency < item1.Latency ? item2 : item1; Console.WriteLine($"Selected best out of two test result:{item.ToString()}"); return(item); }
private void HandleWaitingForTermination() { this.waitingForTerminateCounter += Time.deltaTime; // Check the status every 5 seconds if (waitingForTerminateCounter > 5.0f) { this.waitingForTerminateCounter = 0.0f; Debug.Log("Waiting for other servers in the Task to finish..."); var lambdaConfig = new AmazonLambdaConfig() { RegionEndpoint = this.regionEndpoint }; var lambdaClient = new Amazon.Lambda.AmazonLambdaClient(lambdaConfig); // Call Lambda function to check if we should terminate var taskStatusRequestData = new TaskStatusData(); taskStatusRequestData.taskArn = this.taskDataArn; var request = new Amazon.Lambda.Model.InvokeRequest() { FunctionName = "FargateGameServersCheckIfAllContainersInTaskAreDone", Payload = JsonConvert.SerializeObject(taskStatusRequestData), InvocationType = InvocationType.RequestResponse }; // As we are not doing anything else on the server anymore, we can just wait for the invoke response var invokeResponse = lambdaClient.InvokeAsync(request); invokeResponse.Wait(); invokeResponse.Result.Payload.Position = 0; var sr = new StreamReader(invokeResponse.Result.Payload); var responseString = sr.ReadToEnd(); Debug.Log("Got response: " + responseString); // Try catching to boolean, if it was a failure, this will also result in false var allServersInTaskDone = false; bool.TryParse(responseString, out allServersInTaskDone); if (allServersInTaskDone) { Debug.Log("All servers in the Task done running full amount of sessions --> Terminate"); Application.Quit(); } } }
static void Main(string[] args) { Console.WriteLine("Calling AWS function..."); Amazon.Lambda.AmazonLambdaClient client = new Amazon.Lambda.AmazonLambdaClient(Amazon.RegionEndpoint.EUWest1); var uploadRequest = new UploadRequest { S3BucketName = "afbuckets3", S3ObjectKey = "E033-21_A_PdC_RV_Anna_Monofamiliare_L1_R00.rvt", ForgeBucketKey = "gua68z8svobvpg0r5nizfxvbafna2gbd-ebuilding", ForgeModelName = "FromLambda_Torre A ARCH_20210331_3.rvt" }; var request = new InvokeRequest { FunctionName = "ForgeUploadLocalDeploy-UploadToForgeFunction-1XX2E2GUYTUMQ", // force sync lambda invocation InvocationType = InvocationType.RequestResponse, LogType = LogType.Tail, Payload = JsonSerializer.Serialize(uploadRequest) }; Stopwatch sw = new Stopwatch(); sw.Start(); var response = client.InvokeAsync(request).Result; sw.Stop(); Console.WriteLine($"Function executed in {sw.Elapsed.TotalSeconds} sec"); if (response != null) { using (var sr = new StreamReader(response.Payload)) { var result = sr.ReadToEndAsync().Result; Console.WriteLine(result); var uploadResponse = JsonSerializer.Deserialize <UploadResponse>(result); Console.WriteLine($"object key = {uploadResponse.UploadResult.objectKey}"); } } }
public String DeregisterReportedAMIs(AMICleanupInput input, ILambdaContext context) { var ec2Client = new AmazonEC2Client(); var s3client = new AmazonS3Client(); String[] lines = new AWSCommon().GetS3ContextAsText(input.BucketName, input.Key).Split("\n".ToCharArray()); int index = 0; foreach (String line in lines) { if (input.StartIndex > index) { if (index == input.StartIndex - 1) { context.Logger.LogLine($"Skipped processing up to index #{index}"); } index++; continue; } if (context.RemainingTime.Seconds < 10) { context.Logger.LogLine($"Less than 10 seconds for lambda execution, starting function recursively.."); var lambdaClient = new Amazon.Lambda.AmazonLambdaClient(); input.StartIndex = index; lambdaClient.InvokeAsync(new Amazon.Lambda.Model.InvokeRequest() { InvocationType = Amazon.Lambda.InvocationType.Event, FunctionName = context.FunctionName, Payload = JsonConvert.SerializeObject(input) }).Wait(); return("Started recursively with index=" + index); } index = index + 1; String[] cells = line.Split(','); if (cells.Length >= 3) { String amiId = cells[2]; if (amiId.StartsWith("ami-")) { try { var describeResponse = ec2Client.DescribeImagesAsync(new DescribeImagesRequest() { ImageIds = new List <String>() { amiId } }); describeResponse.Wait(); context.Logger.LogLine($"De-registering AMI {amiId}"); ec2Client.DeregisterImageAsync(new DeregisterImageRequest() { ImageId = amiId }).Wait(); describeResponse.Result.Images[0].BlockDeviceMappings.ForEach(mapping => { if (mapping.Ebs != null && mapping.Ebs.SnapshotId != null) { context.Logger.LogLine($"Deleting snapshot {mapping.Ebs.SnapshotId} for ami {amiId}"); ec2Client.DeleteSnapshotAsync(new DeleteSnapshotRequest() { SnapshotId = mapping.Ebs.SnapshotId }).Wait(); } }); } catch (Exception ex) { context.Logger.LogLine($"Failed to delete ami {amiId} with following error:"); context.Logger.LogLine(ex.ToString()); } } else { context.Logger.LogLine($"Skppingg non-ami id : {amiId}"); } } } return("OK"); }