private void DetermineEnvironment(out string environmentType, out string loadBalancerType) { environmentType = this.GetStringValueOrDefault(this.DeployEnvironmentOptions.EnvironmentType, EBDefinedCommandOptions.ARGUMENT_ENVIRONMENT_TYPE, false); loadBalancerType = this.GetStringValueOrDefault(this.DeployEnvironmentOptions.LoadBalancerType, EBDefinedCommandOptions.ARGUMENT_LOADBALANCER_TYPE, false); if (string.IsNullOrWhiteSpace(environmentType)) { environmentType = string.IsNullOrWhiteSpace(loadBalancerType) ? EBConstants.ENVIRONMENT_TYPE_SINGLEINSTANCE : EBConstants.ENVIRONMENT_TYPE_LOADBALANCED; } if (string.IsNullOrWhiteSpace(loadBalancerType) && EBUtilities.IsLoadBalancedEnvironmentType(environmentType)) { loadBalancerType = EBConstants.LOADBALANCER_TYPE_APPLICATION; } }
private void AddAdditionalOptions(IList <ConfigurationOptionSetting> settings, bool createEnvironmentMode, bool isWindowsEnvironment) { var additionalOptions = this.GetKeyValuePairOrDefault(this.DeployEnvironmentOptions.AdditionalOptions, EBDefinedCommandOptions.ARGUMENT_EB_ADDITIONAL_OPTIONS, false); if (additionalOptions != null && additionalOptions.Count > 0) { foreach (var kvp in additionalOptions) { var tokens = kvp.Key.Split(','); if (tokens.Length != 2) { throw new ToolsException("Additional option \"" + kvp.Key + "=" + kvp.Value + "\" in incorrect format. Format should be <option-namespace>,<option-name>=<option-value>.", ToolsException.CommonErrorCode.DefaultsParseFail); } settings.Add(new ConfigurationOptionSetting { Namespace = tokens[0], OptionName = tokens[1], Value = kvp.Value }); } } var enableXRay = this.GetBoolValueOrDefault(this.DeployEnvironmentOptions.EnableXRay, EBDefinedCommandOptions.ARGUMENT_ENABLE_XRAY, false); if (enableXRay.HasValue) { settings.Add(new ConfigurationOptionSetting() { Namespace = "aws:elasticbeanstalk:xray", OptionName = "XRayEnabled", Value = enableXRay.Value.ToString(CultureInfo.InvariantCulture).ToLowerInvariant() }); this.Logger?.WriteLine($"Enable AWS X-Ray: {enableXRay.Value}"); } var enhancedHealthType = this.GetStringValueOrDefault(this.DeployEnvironmentOptions.EnhancedHealthType, EBDefinedCommandOptions.ARGUMENT_ENHANCED_HEALTH_TYPE, false); if (!string.IsNullOrWhiteSpace(enhancedHealthType)) { if (!EBConstants.ValidEnhanceHealthType.Contains(enhancedHealthType)) { throw new ElasticBeanstalkExceptions($"The enhanced value type {enhancedHealthType} is invalid. Valid values are: {string.Join(", ", EBConstants.ValidEnhanceHealthType)}", ElasticBeanstalkExceptions.EBCode.InvalidEnhancedHealthType); } settings.Add(new ConfigurationOptionSetting() { Namespace = "aws:elasticbeanstalk:healthreporting:system", OptionName = "SystemType", Value = enhancedHealthType }); } string environmentType, loadBalancerType; DetermineEnvironment(out environmentType, out loadBalancerType); var healthCheckURL = this.GetStringValueOrDefault(this.DeployEnvironmentOptions.HealthCheckUrl, EBDefinedCommandOptions.ARGUMENT_HEALTH_CHECK_URL, false); // If creating a new load balanced environment then a heath check url must be set. if (createEnvironmentMode && string.IsNullOrEmpty(healthCheckURL) && EBUtilities.IsLoadBalancedEnvironmentType(environmentType)) { healthCheckURL = "/"; } if (!string.IsNullOrEmpty(healthCheckURL)) { settings.Add(new ConfigurationOptionSetting() { Namespace = "aws:elasticbeanstalk:application", OptionName = "Application Healthcheck URL", Value = healthCheckURL }); if (EBUtilities.IsLoadBalancedEnvironmentType(environmentType) && string.Equals(loadBalancerType, EBConstants.LOADBALANCER_TYPE_APPLICATION)) { settings.Add(new ConfigurationOptionSetting() { Namespace = "aws:elasticbeanstalk:environment:process:default", OptionName = "HealthCheckPath", Value = healthCheckURL }); } } if (!isWindowsEnvironment) { var proxyServer = this.GetStringValueOrDefault(this.DeployEnvironmentOptions.ProxyServer, EBDefinedCommandOptions.ARGUMENT_PROXY_SERVER, false); if (!string.IsNullOrEmpty(proxyServer)) { if (!EBConstants.ValidProxyServer.Contains(proxyServer)) { throw new ElasticBeanstalkExceptions($"The proxy server {proxyServer} is invalid. Valid values are: {string.Join(", ", EBConstants.ValidProxyServer)}", ElasticBeanstalkExceptions.EBCode.InvalidProxyServer); } Logger?.WriteLine($"Configuring reverse proxy to {proxyServer}"); settings.Add(new ConfigurationOptionSetting() { Namespace = OPTIONS_NAMESPACE_ENVIRONMENT_PROXY, OptionName = OPTIONS_NAME_PROXY_SERVER, Value = proxyServer }); } var applicationPort = this.GetIntValueOrDefault(this.DeployEnvironmentOptions.ApplicationPort, EBDefinedCommandOptions.ARGUMENT_APPLICATION_PORT, false); if (applicationPort.HasValue) { Logger?.WriteLine($"Application port to {applicationPort}"); settings.Add(new ConfigurationOptionSetting() { Namespace = OPTIONS_NAMESPACE_APPLICATION_ENVIRONMENT, OptionName = OPTIONS_NAME_APPLICATION_PORT, Value = applicationPort.Value.ToString(CultureInfo.InvariantCulture) }); } } var enableStickySessions = this.GetBoolValueOrDefault(this.DeployEnvironmentOptions.EnableStickySessions, EBDefinedCommandOptions.ARGUMENT_ENABLE_STICKY_SESSIONS, false); if (enableStickySessions.HasValue) { if (enableStickySessions.Value) { Logger?.WriteLine($"Enabling sticky sessions"); } settings.Add(new ConfigurationOptionSetting() { Namespace = "aws:elasticbeanstalk:environment:process:default", OptionName = "StickinessEnabled", Value = enableStickySessions.Value.ToString(CultureInfo.InvariantCulture).ToLowerInvariant() }); } }