示例#1
0
        private async Task UpdateStackParameters(Settings settings, TierModuleDetails module, Dictionary <string, string> parameters)
        {
            // keep all original parameter values except for 'LambdaSharpCoreServices'
            var stackParameters = module.Stack.Parameters
                                  .Select(parameter => {
                if (parameters.TryGetValue(parameter.ParameterKey, out var value))
                {
                    return(new CloudFormationParameter {
                        ParameterKey = parameter.ParameterKey,
                        ParameterValue = value
                    });
                }
                return(new CloudFormationParameter {
                    ParameterKey = parameter.ParameterKey,
                    UsePreviousValue = true
                });
            }).ToList();

            // retrieve name mappings for template
            var template = (await settings.CfnClient.GetTemplateAsync(new GetTemplateRequest {
                StackName = module.Stack.StackName
            })).TemplateBody;
            var nameMappings = new ModelManifestLoader(settings, module.Stack.StackName).GetNameMappingsFromTemplate(template);

            // create change-set
            var now = DateTime.UtcNow;
            var mostRecentStackEventId = await settings.CfnClient.GetMostRecentStackEventIdAsync(module.StackName);

            var changeSetName = $"{module.ModuleDeploymentName}-{now:yyyy-MM-dd-hh-mm-ss}";

            Console.WriteLine();
            Console.WriteLine($"=> Stack update initiated for {module.StackName}");
            var response = await settings.CfnClient.CreateChangeSetAsync(new CreateChangeSetRequest {
                Capabilities        = module.Stack.Capabilities,
                ChangeSetName       = changeSetName,
                ChangeSetType       = (mostRecentStackEventId != null) ? ChangeSetType.UPDATE : ChangeSetType.CREATE,
                Description         = $"Stack parameters update for {module.ModuleReference}",
                Parameters          = stackParameters,
                StackName           = module.StackName,
                UsePreviousTemplate = true,
                Tags = module.Stack.Tags
            });

            try {
                var changes = await WaitForChangeSetAsync(settings, response.Id);

                if (changes == null)
                {
                    LogError($"unable to apply changes to ${module.ModuleDeploymentName}");
                    return;
                }
                if (!changes.Any())
                {
                    Console.WriteLine("=> No stack update required");
                    return;
                }

                // execute change-set
                await settings.CfnClient.ExecuteChangeSetAsync(new ExecuteChangeSetRequest {
                    ChangeSetName = changeSetName,
                    StackName     = module.StackName
                });

                var outcome = await settings.CfnClient.TrackStackUpdateAsync(module.StackName, response.StackId, mostRecentStackEventId, nameMappings, LogError);

                if (outcome.Success)
                {
                    Console.WriteLine($"=> Stack update finished");
                }
                else
                {
                    Console.WriteLine($"=> Stack update FAILED");
                    LogError($"unable to update {module.ModuleDeploymentName}");
                }
            } finally {
                try {
                    await settings.CfnClient.DeleteChangeSetAsync(new DeleteChangeSetRequest {
                        ChangeSetName = response.Id
                    });
                } catch { }
            }
        }
示例#2
0
 //--- Constructors ---
 public DeployStep(Settings settings, string sourceFilename) : base(settings, sourceFilename)
 {
     _loader = new ModelManifestLoader(Settings, sourceFilename);
 }
示例#3
0
 //--- Constructors ---
 public PublishStep(Settings settings, string sourceFilename) : base(settings, sourceFilename)
 {
     _loader          = new ModelManifestLoader(Settings, "cloudformation.json");
     _transferUtility = new TransferUtility(Settings.S3Client);
 }