in ecs-cli/modules/cli/compose/entity/service/service.go [500:608]
func (s *Service) buildCreateServiceInput(serviceName, taskDefName string, desiredCount int) (*ecs.CreateServiceInput, error) {
launchType := s.Context().CommandConfig.LaunchType
cluster := s.Context().CommandConfig.Cluster
ecsParams := s.ecsContext.ECSParams
schedulingStrategy := strings.ToUpper(s.Context().CLIContext.String(flags.SchedulingStrategyFlag))
networkConfig, err := composeutils.ConvertToECSNetworkConfiguration(ecsParams)
if err != nil {
return nil, err
}
placementConstraints, err := composeutils.ConvertToECSPlacementConstraints(ecsParams)
if err != nil {
return nil, err
}
placementStrategy, err := composeutils.ConvertToECSPlacementStrategy(ecsParams)
if err != nil {
return nil, err
}
// NOTE: this validation is not useful if called after GetOrCreateTaskDefinition()
if err = entity.ValidateFargateParams(s.Context().ECSParams, launchType); err != nil {
return nil, err
}
if s.healthCheckGP != nil && s.loadBalancers == nil {
return nil, fmt.Errorf("--%v is only valid for services configured to use load balancers", flags.HealthCheckGracePeriodFlag)
}
createServiceInput := &ecs.CreateServiceInput{
DesiredCount: aws.Int64(int64(desiredCount)), // Required unless DAEMON schedulingStrategy
ServiceName: aws.String(serviceName), // Required
TaskDefinition: aws.String(taskDefName), // Required
Cluster: aws.String(cluster),
DeploymentConfiguration: s.deploymentConfig,
LoadBalancers: s.loadBalancers,
Role: aws.String(s.role),
}
// TODO: revert to "LATEST" when latest refers to 1.4.0
if launchType == config.LaunchTypeFargate && ecsParams != nil && len(ecsParams.TaskDefinition.EFSVolumes) > 0 {
log.Warnf("Detected an EFS Volume in task definition %s", taskDefName)
log.Warnf("Using Fargate platform version %s, which includes changes to the networking flows for VPC endpoint customers.", config.PlatformVersion140)
log.Warn("Learn more: https://aws.amazon.com/blogs/containers/aws-fargate-launches-platform-version-1-4/")
createServiceInput.PlatformVersion = aws.String(config.PlatformVersion140)
}
if schedulingStrategy != "" {
createServiceInput.SchedulingStrategy = aws.String(schedulingStrategy)
if schedulingStrategy == ecs.SchedulingStrategyDaemon {
createServiceInput.DesiredCount = nil
}
}
if s.healthCheckGP != nil {
createServiceInput.HealthCheckGracePeriodSeconds = aws.Int64(*s.healthCheckGP)
}
if len(s.serviceRegistries) > 0 {
createServiceInput.ServiceRegistries = s.serviceRegistries
}
if networkConfig != nil {
createServiceInput.NetworkConfiguration = networkConfig
}
if placementConstraints != nil {
createServiceInput.PlacementConstraints = placementConstraints
}
if placementStrategy != nil {
createServiceInput.PlacementStrategy = placementStrategy
}
if launchType != "" {
createServiceInput.LaunchType = aws.String(launchType)
}
if err = createServiceInput.Validate(); err != nil {
return nil, err
}
tags, err := s.GetTags()
if err != nil {
return nil, err
}
if len(tags) > 0 {
createServiceInput.Tags = tags
}
arnEnabled, err := isTaskLongARNEnabled(s.Context().ECSClient)
if err != nil {
return nil, err
}
if arnEnabled {
// Even if the customer didn't create the service with tags, we enable propogation
// So that later, if the customer updates to a new task def that has tags,
// those tags will be propogated to tasks
createServiceInput.PropagateTags = aws.String(ecs.PropagateTagsTaskDefinition)
}
if !s.Context().CLIContext.Bool(flags.DisableECSManagedTagsFlag) {
if arnEnabled {
log.Info("Auto-enabling ECS Managed Tags")
createServiceInput.EnableECSManagedTags = aws.Bool(true)
}
}
return createServiceInput, nil
}