in src/AWS.Deploy.Recipes/CdkTemplates/AspNetAppAppRunner/Generated/Recipe.cs [144:240]
private void ConfigureAppRunnerService(IRecipeProps<Configuration> props)
{
if (ServiceAccessRole == null)
throw new InvalidOperationException($"{nameof(ServiceAccessRole)} has not been set. The {nameof(ConfigureIAMRoles)} method should be called before {nameof(ConfigureAppRunnerService)}");
if (TaskRole == null)
throw new InvalidOperationException($"{nameof(TaskRole)} has not been set. The {nameof(ConfigureIAMRoles)} method should be called before {nameof(ConfigureAppRunnerService)}");
if (string.IsNullOrEmpty(props.ECRRepositoryName))
throw new InvalidOrMissingConfigurationException("The provided ECR Repository Name is null or empty.");
var ecrRepository = Repository.FromRepositoryName(this, "ECRRepository", props.ECRRepositoryName);
Configuration settings = props.Settings;
var runtimeEnvironmentVariables = new List<CfnService.IKeyValuePairProperty>();
foreach (var variable in settings.AppRunnerEnvironmentVariables)
{
runtimeEnvironmentVariables.Add(new CfnService.KeyValuePairProperty
{
Name = variable.Key,
Value = variable.Value
});
}
var appRunnerServiceProp = new CfnServiceProps
{
ServiceName = settings.ServiceName,
SourceConfiguration = new CfnService.SourceConfigurationProperty
{
AuthenticationConfiguration = new CfnService.AuthenticationConfigurationProperty
{
AccessRoleArn = ServiceAccessRole.RoleArn
},
ImageRepository = new CfnService.ImageRepositoryProperty
{
ImageRepositoryType = "ECR",
ImageIdentifier = ContainerImage.FromEcrRepository(ecrRepository, props.ECRImageTag).ImageName,
ImageConfiguration = new CfnService.ImageConfigurationProperty
{
Port = settings.Port.ToString(),
StartCommand = !string.IsNullOrWhiteSpace(settings.StartCommand) ? settings.StartCommand : null,
RuntimeEnvironmentVariables = runtimeEnvironmentVariables.ToArray()
}
}
}
};
if (settings.VPCConnector.UseVPCConnector)
{
appRunnerServiceProp.NetworkConfiguration = new CfnService.NetworkConfigurationProperty
{
EgressConfiguration = new CfnService.EgressConfigurationProperty
{
EgressType = "VPC",
VpcConnectorArn = VPCConnector != null ? VPCConnector.AttrVpcConnectorArn : settings.VPCConnector.VpcConnectorId
}
};
}
if (!string.IsNullOrEmpty(settings.EncryptionKmsKey))
{
var encryptionConfig = new CfnService.EncryptionConfigurationProperty();
appRunnerServiceProp.EncryptionConfiguration = encryptionConfig;
encryptionConfig.KmsKey = settings.EncryptionKmsKey;
}
var healthCheckConfig = new CfnService.HealthCheckConfigurationProperty();
appRunnerServiceProp.HealthCheckConfiguration = healthCheckConfig;
healthCheckConfig.HealthyThreshold = settings.HealthCheckHealthyThreshold;
healthCheckConfig.Interval = settings.HealthCheckInterval;
healthCheckConfig.Protocol = settings.HealthCheckProtocol;
healthCheckConfig.Timeout = settings.HealthCheckTimeout;
healthCheckConfig.UnhealthyThreshold = settings.HealthCheckUnhealthyThreshold;
if (string.Equals(healthCheckConfig.Protocol, "HTTP"))
{
healthCheckConfig.Path = string.IsNullOrEmpty(settings.HealthCheckPath) ? "/" : settings.HealthCheckPath;
}
var instanceConfig = new CfnService.InstanceConfigurationProperty();
appRunnerServiceProp.InstanceConfiguration = instanceConfig;
instanceConfig.InstanceRoleArn = TaskRole.RoleArn;
instanceConfig.Cpu = settings.Cpu;
instanceConfig.Memory = settings.Memory;
AppRunnerService = new CfnService(this, nameof(AppRunnerService), InvokeCustomizeCDKPropsEvent(nameof(AppRunnerService), this, appRunnerServiceProp));
var output = new CfnOutput(this, "EndpointURL", new CfnOutputProps
{
Value = $"https://{AppRunnerService.AttrServiceUrl}/"
});
}