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, IApplicationLoadBalancerTarget, INetworkLoadBalancerTarget, ILoadBalancerTarget, IConnectable
Syntax (vb)
Public MustInherit Class BaseService
Inherits Resource
Implements IBaseService, IService, IResource, 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(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
BaseService(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
BaseService(Construct, String, IBaseServiceProps, Object, TaskDefinition) | Constructs a new instance of the BaseService class. |
Properties
CloudmapService | |
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. |
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
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, Nullable<Boolean>, 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. |
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(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(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected BaseService(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
BaseService(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected BaseService(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
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 Constructs.Construct
- id System.String
- props IBaseServiceProps
- additionalProps System.Object
- taskDefinition TaskDefinition
Properties
CloudmapService
CloudMapService
The details of the AWS Cloud Map service.
public virtual IService CloudMapService { get; }
Property Value
Cluster
The cluster that hosts the service.
public virtual ICluster Cluster { get; }
Property Value
Connections
The security groups which manage the allowed network traffic for the service.
public virtual Connections_ Connections { get; }
Property Value
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
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
CfnService.ILoadBalancerProperty[]
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
ServiceArn
The Amazon Resource Name (ARN) of the service.
public virtual string ServiceArn { get; }
Property Value
System.String
ServiceName
The name of the service.
public virtual string ServiceName { get; }
Property Value
System.String
Remarks
Attribute: true
ServiceRegistries
The details of the service discovery registries to assign to this service.
protected virtual CfnService.IServiceRegistryProperty[] ServiceRegistries { get; set; }
Property Value
CfnService.IServiceRegistryProperty[]
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
Methods
AddVolume(ServiceManagedVolume)
Adds a volume to the Service.
public virtual void AddVolume(ServiceManagedVolume volume)
Parameters
- volume ServiceManagedVolume
AssociateCloudMapService(IAssociateCloudMapServiceOptions)
Associates this service with a CloudMap service.
public virtual void AssociateCloudMapService(IAssociateCloudMapServiceOptions options)
Parameters
- options IAssociateCloudMapServiceOptions
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
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
ConfigureAwsVpcNetworkingWithSecurityGroups(IVpc, Nullable<Boolean>, ISubnetSelection, ISecurityGroup[])
This method is called to create a networkConfiguration.
protected virtual void ConfigureAwsVpcNetworkingWithSecurityGroups(IVpc vpc, Nullable<bool> assignPublicIp = null, ISubnetSelection vpcSubnets = null, ISecurityGroup[] securityGroups = null)
Parameters
- vpc IVpc
- assignPublicIp System.Nullable<System.Boolean>
- vpcSubnets ISubnetSelection
- securityGroups ISecurityGroup[]
EnableCloudMap(ICloudMapOptions)
Enable CloudMap service discovery for the service.
public virtual Service EnableCloudMap(ICloudMapOptions options)
Parameters
- options ICloudMapOptions
Returns
The created CloudMap service
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 System.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
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
- scope Constructs.Construct
- id System.String
- serviceArn System.String
Returns
Remarks
The format is the "new" format "arn:aws:ecs:region:aws_account_id:service/cluster-name/service-name".
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 System.String
- props IMetricOptions
Returns
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(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
})
});