Class BaseService
The base class for Ec2Service and FargateService services.
Implements
Inherited Members
Namespace: Amazon.CDK.AWS.ECS
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public abstract class BaseService : Resource, IBaseService, IService, IResource, IServiceRef, IConstruct, IDependable, IEnvironmentAware, IApplicationLoadBalancerTarget, INetworkLoadBalancerTarget, ILoadBalancerTarget, IConnectable
Syntax (vb)
Public MustInherit Class BaseService Inherits Resource Implements IBaseService, IService, IResource, IServiceRef, IConstruct, IDependable, IEnvironmentAware, IApplicationLoadBalancerTarget, INetworkLoadBalancerTarget, ILoadBalancerTarget, IConnectable
Remarks
ExampleMetadata: infused
Examples
using Amazon.CDK.AWS.ECS;
var service = BaseService.FromServiceArnWithCluster(this, "EcsService", "arn:aws:ecs:us-east-1:123456789012:service/myClusterName/myServiceName");
var pipeline = new Pipeline(this, "MyPipeline");
var buildOutput = new Artifact();
// add source and build stages to the pipeline as usual...
var deployStage = pipeline.AddStage(new StageOptions {
StageName = "Deploy",
Actions = new [] {
new EcsDeployAction(new EcsDeployActionProps {
ActionName = "DeployAction",
Service = service,
Input = buildOutput
}) }
});
Synopsis
Constructors
| BaseService(Construct, string, IBaseServiceProps, object, TaskDefinition) | Constructs a new instance of the BaseService class. |
Properties
| CloudMapService | The CloudMap service created for this service, if any. |
| CloudmapService | The details of the AWS Cloud Map service. |
| Cluster | The cluster that hosts the service. |
| Connections | The security groups which manage the allowed network traffic for the service. |
| DeploymentAlarms | The deployment alarms property - this will be rendered directly and lazily as the CfnService.alarms property. |
| LoadBalancers | A list of Elastic Load Balancing load balancer objects, containing the load balancer name, the container name (as it appears in a container definition), and the container port to access from the load balancer. |
| NetworkConfiguration | A list of Elastic Load Balancing load balancer objects, containing the load balancer name, the container name (as it appears in a container definition), and the container port to access from the load balancer. |
| ServiceArn | The Amazon Resource Name (ARN) of the service. |
| ServiceName | The name of the service. |
| ServiceRef | A reference to this service. |
| ServiceRegistries | The details of the service discovery registries to assign to this service. |
| TaskDefinition | The task definition to use for tasks in the service. |
Methods
| AddLifecycleHook(IDeploymentLifecycleHookTarget) | Add a deployment lifecycle hook target. |
| AddVolume(ServiceManagedVolume) | Adds a volume to the Service. |
| AssociateCloudMapService(IAssociateCloudMapServiceOptions) | Associates this service with a CloudMap service. |
| AttachToApplicationTargetGroup(IApplicationTargetGroup) | This method is called to attach this service to an Application Load Balancer. |
| AttachToClassicLB(LoadBalancer) | Registers the service as a target of a Classic Load Balancer (CLB). |
| AttachToNetworkTargetGroup(INetworkTargetGroup) | This method is called to attach this service to a Network Load Balancer. |
| AutoScaleTaskCount(IEnableScalingProps) | An attribute representing the minimum and maximum task count for an AutoScalingGroup. |
| ConfigureAwsVpcNetworkingWithSecurityGroups(IVpc, bool?, ISubnetSelection?, ISecurityGroup[]?) | This method is called to create a networkConfiguration. |
| EnableCloudMap(ICloudMapOptions) | Enable CloudMap service discovery for the service. |
| EnableDeploymentAlarms(string[], IDeploymentAlarmOptions?) | Enable Deployment Alarms which take advantage of arbitrary alarms and configure them after service initialization. |
| EnableServiceConnect(IServiceConnectProps?) | Enable Service Connect on this service. |
| FromServiceArnWithCluster(Construct, string, string) | Import an existing ECS/Fargate Service using the service cluster format. |
| IsUsingECSDeploymentController() | Checks if the service is using the ECS deployment controller. |
| LoadBalancerTarget(ILoadBalancerTargetOptions) | Return a load balancing target for a specific container and port. |
| Metric(string, IMetricOptions?) | This method returns the specified CloudWatch metric name for this service. |
| MetricCpuUtilization(IMetricOptions?) | This method returns the CloudWatch metric for this service's CPU utilization. |
| MetricMemoryUtilization(IMetricOptions?) | This method returns the CloudWatch metric for this service's memory utilization. |
| RegisterLoadBalancerTargets(params IEcsTarget[]) | Use this function to create all load balancer targets to be registered in this service, add them to target groups, and attach target groups to listeners accordingly. |
Constructors
BaseService(Construct, string, IBaseServiceProps, object, TaskDefinition)
Constructs a new instance of the BaseService class.
protected BaseService(Construct scope, string id, IBaseServiceProps props, object additionalProps, TaskDefinition taskDefinition)
Parameters
- scope Construct
- id string
- props IBaseServiceProps
- additionalProps object
- taskDefinition TaskDefinition
Remarks
ExampleMetadata: infused
Properties
CloudMapService
The CloudMap service created for this service, if any.
public virtual IService? CloudMapService { get; }
Property Value
Remarks
ExampleMetadata: infused
CloudmapService
The details of the AWS Cloud Map service.
protected virtual Service? CloudmapService { get; set; }
Property Value
Remarks
ExampleMetadata: infused
Cluster
The cluster that hosts the service.
public virtual ICluster Cluster { get; }
Property Value
Remarks
ExampleMetadata: infused
Connections
The security groups which manage the allowed network traffic for the service.
public virtual Connections_ Connections { get; }
Property Value
Remarks
ExampleMetadata: infused
DeploymentAlarms
The deployment alarms property - this will be rendered directly and lazily as the CfnService.alarms property.
protected virtual CfnService.IDeploymentAlarmsProperty? DeploymentAlarms { get; set; }
Property Value
CfnService.IDeploymentAlarmsProperty
Remarks
ExampleMetadata: infused
LoadBalancers
A list of Elastic Load Balancing load balancer objects, containing the load balancer name, the container name (as it appears in a container definition), and the container port to access from the load balancer.
protected virtual CfnService.ILoadBalancerProperty[] LoadBalancers { get; set; }
Property Value
Remarks
ExampleMetadata: infused
NetworkConfiguration
A list of Elastic Load Balancing load balancer objects, containing the load balancer name, the container name (as it appears in a container definition), and the container port to access from the load balancer.
protected virtual CfnService.INetworkConfigurationProperty? NetworkConfiguration { get; set; }
Property Value
CfnService.INetworkConfigurationProperty
Remarks
ExampleMetadata: infused
ServiceArn
The Amazon Resource Name (ARN) of the service.
public virtual string ServiceArn { get; }
Property Value
Remarks
ExampleMetadata: infused
ServiceName
The name of the service.
public virtual string ServiceName { get; }
Property Value
Remarks
ExampleMetadata: infused
ServiceRef
A reference to this service.
public virtual IServiceReference ServiceRef { get; }
Property Value
Remarks
ExampleMetadata: infused
ServiceRegistries
The details of the service discovery registries to assign to this service.
protected virtual CfnService.IServiceRegistryProperty[] ServiceRegistries { get; set; }
Property Value
Remarks
For more information, see Service Discovery.
TaskDefinition
The task definition to use for tasks in the service.
public virtual TaskDefinition TaskDefinition { get; }
Property Value
Remarks
ExampleMetadata: infused
Methods
AddLifecycleHook(IDeploymentLifecycleHookTarget)
Add a deployment lifecycle hook target.
public virtual void AddLifecycleHook(IDeploymentLifecycleHookTarget target)
Parameters
- target IDeploymentLifecycleHookTarget
The lifecycle hook target to add.
Remarks
ExampleMetadata: infused
AddVolume(ServiceManagedVolume)
Adds a volume to the Service.
public virtual void AddVolume(ServiceManagedVolume volume)
Parameters
- volume ServiceManagedVolume
Remarks
ExampleMetadata: infused
AssociateCloudMapService(IAssociateCloudMapServiceOptions)
Associates this service with a CloudMap service.
public virtual void AssociateCloudMapService(IAssociateCloudMapServiceOptions options)
Parameters
- options IAssociateCloudMapServiceOptions
Remarks
ExampleMetadata: infused
AttachToApplicationTargetGroup(IApplicationTargetGroup)
This method is called to attach this service to an Application Load Balancer.
public virtual ILoadBalancerTargetProps AttachToApplicationTargetGroup(IApplicationTargetGroup targetGroup)
Parameters
- targetGroup IApplicationTargetGroup
Returns
Remarks
Don't call this function directly. Instead, call listener.addTargets()
to add this service to a load balancer.
AttachToClassicLB(LoadBalancer)
Registers the service as a target of a Classic Load Balancer (CLB).
public virtual void AttachToClassicLB(LoadBalancer loadBalancer)
Parameters
- loadBalancer LoadBalancer
[disable-awslint:ref-via-interface].
Remarks
Don't call this. Call loadBalancer.addTarget() instead.
AttachToNetworkTargetGroup(INetworkTargetGroup)
This method is called to attach this service to a Network Load Balancer.
public virtual ILoadBalancerTargetProps AttachToNetworkTargetGroup(INetworkTargetGroup targetGroup)
Parameters
- targetGroup INetworkTargetGroup
Returns
Remarks
Don't call this function directly. Instead, call listener.addTargets()
to add this service to a load balancer.
AutoScaleTaskCount(IEnableScalingProps)
An attribute representing the minimum and maximum task count for an AutoScalingGroup.
public virtual ScalableTaskCount AutoScaleTaskCount(IEnableScalingProps props)
Parameters
- props IEnableScalingProps
Returns
Remarks
ExampleMetadata: infused
ConfigureAwsVpcNetworkingWithSecurityGroups(IVpc, bool?, ISubnetSelection?, ISecurityGroup[]?)
This method is called to create a networkConfiguration.
protected virtual void ConfigureAwsVpcNetworkingWithSecurityGroups(IVpc vpc, bool? assignPublicIp = null, ISubnetSelection? vpcSubnets = null, ISecurityGroup[]? securityGroups = null)
Parameters
- vpc IVpc
- assignPublicIp bool?
- vpcSubnets ISubnetSelection
- securityGroups ISecurityGroup[]
Remarks
ExampleMetadata: infused
EnableCloudMap(ICloudMapOptions)
Enable CloudMap service discovery for the service.
public virtual Service EnableCloudMap(ICloudMapOptions options)
Parameters
- options ICloudMapOptions
Returns
The created CloudMap service
Remarks
ExampleMetadata: infused
EnableDeploymentAlarms(string[], IDeploymentAlarmOptions?)
Enable Deployment Alarms which take advantage of arbitrary alarms and configure them after service initialization.
public virtual void EnableDeploymentAlarms(string[] alarmNames, IDeploymentAlarmOptions? options = null)
Parameters
- alarmNames string[]
- options IDeploymentAlarmOptions
Remarks
If you have already enabled deployment alarms, this function can be used to tell ECS about additional alarms that should interrupt a deployment.
New alarms specified in subsequent calls of this function will be appended to the existing list of alarms.
The same Alarm Behavior must be used on all deployment alarms. If you specify different AlarmBehavior values in multiple calls to this function, or the Alarm Behavior used here doesn't match the one used in the service constructor, an error will be thrown.
If the alarm's metric references the service, you cannot pass Alarm.alarmName here. That will cause a circular
dependency between the service and its deployment alarm. See this package's README for options to alarm on service
metrics, and avoid this circular dependency.
EnableServiceConnect(IServiceConnectProps?)
Enable Service Connect on this service.
public virtual void EnableServiceConnect(IServiceConnectProps? config = null)
Parameters
- config IServiceConnectProps
Remarks
ExampleMetadata: infused
FromServiceArnWithCluster(Construct, string, string)
Import an existing ECS/Fargate Service using the service cluster format.
public static IBaseService FromServiceArnWithCluster(Construct scope, string id, string serviceArn)
Parameters
Returns
Remarks
The format is the "new" format "arn:aws:ecs:region:aws_account_id:service/cluster-name/service-name".
IsUsingECSDeploymentController()
Checks if the service is using the ECS deployment controller.
public virtual bool IsUsingECSDeploymentController()
Returns
true if the service is using the ECS deployment controller or if no deployment controller is specified (defaults to ECS)
Remarks
ExampleMetadata: infused
LoadBalancerTarget(ILoadBalancerTargetOptions)
Return a load balancing target for a specific container and port.
public virtual IEcsLoadBalancerTarget LoadBalancerTarget(ILoadBalancerTargetOptions options)
Parameters
- options ILoadBalancerTargetOptions
Returns
Remarks
Use this function to create a load balancer target if you want to load balance to another container than the first essential container or the first mapped port on the container.
Use the return value of this function where you would normally use a load balancer
target, instead of the Service object itself.
Examples
ApplicationListener listener;
BaseService service;
listener.AddTargets("ECS", new AddApplicationTargetsProps {
Port = 80,
Targets = new [] { service.LoadBalancerTarget(new LoadBalancerTargetOptions {
ContainerName = "MyContainer",
ContainerPort = 1234
}) }
});
Metric(string, IMetricOptions?)
This method returns the specified CloudWatch metric name for this service.
public virtual Metric Metric(string metricName, IMetricOptions? props = null)
Parameters
- metricName string
- props IMetricOptions
Returns
Remarks
ExampleMetadata: infused
MetricCpuUtilization(IMetricOptions?)
This method returns the CloudWatch metric for this service's CPU utilization.
public virtual Metric MetricCpuUtilization(IMetricOptions? props = null)
Parameters
- props IMetricOptions
Returns
Remarks
Default: average over 5 minutes
MetricMemoryUtilization(IMetricOptions?)
This method returns the CloudWatch metric for this service's memory utilization.
public virtual Metric MetricMemoryUtilization(IMetricOptions? props = null)
Parameters
- props IMetricOptions
Returns
Remarks
Default: average over 5 minutes
RegisterLoadBalancerTargets(params IEcsTarget[])
Use this function to create all load balancer targets to be registered in this service, add them to target groups, and attach target groups to listeners accordingly.
public virtual void RegisterLoadBalancerTargets(params IEcsTarget[] targets)
Parameters
- targets IEcsTarget[]
Remarks
Alternatively, you can use listener.addTargets() to create targets and add them to target groups.
Examples
ApplicationListener listener;
BaseService service;
service.RegisterLoadBalancerTargets(new EcsTarget {
ContainerName = "web",
ContainerPort = 80,
NewTargetGroupId = "ECS",
Listener = ListenerConfig.ApplicationListener(listener, new AddApplicationTargetsProps {
Protocol = ApplicationProtocol.HTTPS
})
});