in src/AWS.Deploy.Recipes/CdkTemplates/AspNetAppElasticBeanstalkLinux/Generated/Recipe.cs [128:346]
private void ConfigureBeanstalkEnvironment(Configuration settings)
{
if (Ec2InstanceProfile == null)
throw new InvalidOperationException($"{nameof(Ec2InstanceProfile)} has not been set. The {nameof(ConfigureIAM)} method should be called before {nameof(ConfigureBeanstalkEnvironment)}");
if (ApplicationVersion == null)
throw new InvalidOperationException($"{nameof(ApplicationVersion)} has not been set. The {nameof(ConfigureApplication)} method should be called before {nameof(ConfigureBeanstalkEnvironment)}");
var optionSettingProperties = new List<CfnEnvironment.OptionSettingProperty> {
new CfnEnvironment.OptionSettingProperty {
Namespace = "aws:autoscaling:launchconfiguration",
OptionName = "IamInstanceProfile",
Value = Ec2InstanceProfile.AttrArn
},
new CfnEnvironment.OptionSettingProperty {
Namespace = "aws:elasticbeanstalk:environment",
OptionName = "EnvironmentType",
Value = settings.EnvironmentType
},
new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:elasticbeanstalk:managedactions",
OptionName = "ManagedActionsEnabled",
Value = settings.ElasticBeanstalkManagedPlatformUpdates.ManagedActionsEnabled.ToString().ToLower()
},
new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:elasticbeanstalk:xray",
OptionName = "XRayEnabled",
Value = settings.XRayTracingSupportEnabled.ToString().ToLower()
},
new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:elasticbeanstalk:healthreporting:system",
OptionName = "SystemType",
Value = settings.EnhancedHealthReporting
}
};
if (!string.IsNullOrEmpty(settings.InstanceType))
{
optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:autoscaling:launchconfiguration",
OptionName = "InstanceType",
Value = settings.InstanceType
});
}
if (settings.EnvironmentType.Equals(ENVIRONMENTTYPE_LOADBALANCED))
{
optionSettingProperties.Add(
new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:elasticbeanstalk:environment",
OptionName = "LoadBalancerType",
Value = settings.LoadBalancerType
}
);
if (!string.IsNullOrEmpty(settings.HealthCheckURL))
{
optionSettingProperties.Add(
new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:elasticbeanstalk:application",
OptionName = "Application Healthcheck URL",
Value = settings.HealthCheckURL
}
);
optionSettingProperties.Add(
new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:elasticbeanstalk:environment:process:default",
OptionName = "HealthCheckPath",
Value = settings.HealthCheckURL
}
);
}
}
if (!string.IsNullOrEmpty(settings.EC2KeyPair))
{
optionSettingProperties.Add(
new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:autoscaling:launchconfiguration",
OptionName = "EC2KeyName",
Value = settings.EC2KeyPair
}
);
}
if (settings.ElasticBeanstalkManagedPlatformUpdates.ManagedActionsEnabled)
{
BeanstalkServiceRole = new Role(this, nameof(BeanstalkServiceRole), InvokeCustomizeCDKPropsEvent(nameof(BeanstalkServiceRole), this, new RoleProps
{
AssumedBy = new ServicePrincipal("elasticbeanstalk.amazonaws.com"),
ManagedPolicies = new[]
{
ManagedPolicy.FromAwsManagedPolicyName("AWSElasticBeanstalkManagedUpdatesCustomerRolePolicy")
}
}));
optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:elasticbeanstalk:environment",
OptionName = "ServiceRole",
Value = BeanstalkServiceRole.RoleArn
});
optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:elasticbeanstalk:managedactions",
OptionName = "PreferredStartTime",
Value = settings.ElasticBeanstalkManagedPlatformUpdates.PreferredStartTime
});
optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:elasticbeanstalk:managedactions:platformupdate",
OptionName = "UpdateLevel",
Value = settings.ElasticBeanstalkManagedPlatformUpdates.UpdateLevel
});
}
if (!string.IsNullOrEmpty(settings.ReverseProxy))
{
optionSettingProperties.Add(
new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:elasticbeanstalk:environment:proxy",
OptionName = "ProxyServer",
Value = settings.ReverseProxy
}
);
}
if (settings.ElasticBeanstalkRollingUpdates.RollingUpdatesEnabled)
{
optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:autoscaling:updatepolicy:rollingupdate",
OptionName = "RollingUpdateEnabled",
Value = settings.ElasticBeanstalkRollingUpdates.RollingUpdatesEnabled.ToString().ToLower()
});
optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:autoscaling:updatepolicy:rollingupdate",
OptionName = "RollingUpdateType",
Value = settings.ElasticBeanstalkRollingUpdates.RollingUpdateType
});
optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:autoscaling:updatepolicy:rollingupdate",
OptionName = "Timeout",
Value = settings.ElasticBeanstalkRollingUpdates.Timeout
});
if (settings.ElasticBeanstalkRollingUpdates.MaxBatchSize != null)
{
optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:autoscaling:updatepolicy:rollingupdate",
OptionName = "MaxBatchSize",
Value = settings.ElasticBeanstalkRollingUpdates.MaxBatchSize.ToString()
});
}
if (settings.ElasticBeanstalkRollingUpdates.MinInstancesInService != null)
{
optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:autoscaling:updatepolicy:rollingupdate",
OptionName = "MinInstancesInService",
Value = settings.ElasticBeanstalkRollingUpdates.MinInstancesInService.ToString()
});
}
if (settings.ElasticBeanstalkRollingUpdates.PauseTime != null)
{
optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:autoscaling:updatepolicy:rollingupdate",
OptionName = "PauseTime",
Value = settings.ElasticBeanstalkRollingUpdates.PauseTime
});
}
}
if (settings.ElasticBeanstalkEnvironmentVariables != null)
{
foreach (var (key, value) in settings.ElasticBeanstalkEnvironmentVariables)
{
optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:elasticbeanstalk:application:environment",
OptionName = key,
Value = value
});
}
}
if (!settings.BeanstalkEnvironment.CreateNew)
throw new InvalidOrMissingConfigurationException("The ability to deploy an Elastic Beanstalk application to an existing environment via a new CloudFormation stack is not supported yet.");
BeanstalkEnvironment = new CfnEnvironment(this, nameof(BeanstalkEnvironment), InvokeCustomizeCDKPropsEvent(nameof(BeanstalkEnvironment), this, new CfnEnvironmentProps
{
EnvironmentName = settings.BeanstalkEnvironment.EnvironmentName,
ApplicationName = settings.BeanstalkApplication.ApplicationName,
PlatformArn = settings.ElasticBeanstalkPlatformArn,
OptionSettings = optionSettingProperties.ToArray(),
CnamePrefix = !string.IsNullOrEmpty(settings.CNamePrefix) ? settings.CNamePrefix : null,
// This line is critical - reference the label created in this same stack
VersionLabel = ApplicationVersion.Ref,
}));
}