private async Task <string> UploadTemplateFileAsync(ModuleManifest manifest, string description) { var moduleInfo = manifest.ModuleInfo; // rewrite artifacts in manifest to have an absolute path manifest.Artifacts = manifest.Artifacts .OrderBy(artifact => artifact) .Select(artifact => moduleInfo.GetArtifactPath(artifact)).ToList(); // add template to list of artifacts var destinationKey = manifest.GetModuleTemplatePath(); manifest.Artifacts.Insert(0, destinationKey); // update cloudformation template with manifest and minify it var template = File.ReadAllText(SourceFilename) .Replace(ModuleInfo.MODULE_ORIGIN_PLACEHOLDER, moduleInfo.Origin ?? throw new ApplicationException("missing Origin information")); var cloudformation = JObject.Parse(template); ((JObject)cloudformation["Metadata"])["LambdaSharp::Manifest"] = JObject.FromObject(manifest, new JsonSerializer { NullValueHandling = NullValueHandling.Ignore }); var minified = JsonConvert.SerializeObject(cloudformation, new JsonSerializerSettings { Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore }); // upload minified json if (_forcePublish || !await DoesS3ObjectExistsAsync(destinationKey)) { Console.WriteLine($"=> Uploading {description}: {Path.GetFileName(destinationKey)}"); var request = new TransferUtilityUploadRequest { InputStream = new MemoryStream(Encoding.UTF8.GetBytes(minified)), BucketName = Settings.DeploymentBucketName, ContentType = "application/json", Key = destinationKey }; request.Metadata[AMAZON_METADATA_ORIGIN] = Settings.DeploymentBucketName; try { await _transferUtility.UploadAsync(request); _changesDetected = true; } catch (AmazonS3Exception e) when(e.Message == "The XML you provided was not well-formed or did not validate against our published schema") { // NOTE (2019-09-14, bjorg): this exception can occur on slow/unreliable networks LogError("unable to upload template due to a network error"); } } return(destinationKey); }
private async Task <string> UploadTemplateFileAsync(ModuleManifest manifest, string description) { var moduleInfo = manifest.ModuleInfo; // rewrite artifacts in manifest to have an absolute path manifest.Artifacts = manifest.Artifacts .OrderBy(artifact => artifact) .Select(artifact => moduleInfo.GetArtifactPath(artifact)).ToList(); // add template to list of artifacts var destinationKey = manifest.GetModuleTemplatePath(); manifest.Artifacts.Insert(0, destinationKey); // update cloudformation template with manifest and minify it var template = File.ReadAllText(SourceFilename) .Replace(ModuleInfo.MODULE_ORIGIN_PLACEHOLDER, moduleInfo.Origin ?? throw new ApplicationException("missing Origin information")); var cloudformation = JObject.Parse(template); ((JObject)cloudformation["Metadata"])["LambdaSharp::Manifest"] = JObject.FromObject(manifest, new JsonSerializer { NullValueHandling = NullValueHandling.Ignore }); var minified = JsonConvert.SerializeObject(cloudformation, new JsonSerializerSettings { Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore }); // upload minified json if (_forcePublish || !await DoesS3ObjectExistsAsync(destinationKey)) { Console.WriteLine($"=> Uploading {description}: s3://{Settings.DeploymentBucketName}/{destinationKey}"); var request = new TransferUtilityUploadRequest { InputStream = new MemoryStream(Encoding.UTF8.GetBytes(minified)), BucketName = Settings.DeploymentBucketName, ContentType = "application/json", Key = destinationKey }; request.Metadata[AMAZON_METADATA_ORIGIN] = Settings.DeploymentBucketName; await _transferUtility.UploadAsync(request); _changesDetected = true; } return(destinationKey); }