private async Task UpdateApiDeploymentAsync(CancellationToken cancellationToken) { // list current deployments LogInfo("Listing deployments"); var deploymentsResponse = await _apiGatewayClient.GetDeploymentsAsync(new GetDeploymentsRequest { RestApiId = _restApiId }); LogInfo($"Found {deploymentsResponse.Items.Count:N0} deployments"); // create a new deployment LogInfo("Creating a new deployment"); var createResponse = await _apiGatewayClient.CreateDeploymentAsync(new CreateDeploymentRequest { RestApiId = _restApiId, Description = $"{Info.ModuleId} LambdaSharp App API (update)" }); LogInfo($"New deployment created: id={createResponse.Id}"); // update stage to use new deployment LogInfo("Updating stage"); await _apiGatewayClient.UpdateStageAsync(new UpdateStageRequest { RestApiId = _restApiId, StageName = _stageName, PatchOperations = { new PatchOperation { Op = Op.Replace, Path = "/deploymentId", Value = createResponse.Id } } }); // remove all previous deployments, except one oldest which is managed by CloudFormation var deploymentsToDelete = deploymentsResponse.Items.OrderByDescending(deployment => deployment.CreatedDate).SkipLast(1).ToList(); if (deploymentsToDelete.Any()) { LogInfo("Deleting old deployments"); foreach (var deployment in deploymentsToDelete) { LogInfo($"Deleting deployment: id={deployment.Id}"); await _apiGatewayClient.DeleteDeploymentAsync(new DeleteDeploymentRequest { RestApiId = _restApiId, DeploymentId = deployment.Id }); } } }
private Amazon.APIGateway.Model.CreateDeploymentResponse CallAWSServiceOperation(IAmazonAPIGateway client, Amazon.APIGateway.Model.CreateDeploymentRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon API Gateway", "CreateDeployment"); try { #if DESKTOP return(client.CreateDeployment(request)); #elif CORECLR return(client.CreateDeploymentAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }