Class BaseService
The base class for Ec2Service and FargateService services.
Implements
Inherited Members
Namespace: Amazon.CDK.AWS.ECS
Assembly: Amazon.CDK.AWS.ECS.dll
Syntax (csharp)
public abstract class BaseService : Resource, IBaseService, IService, IResource, IConstruct, IDependable, IApplicationLoadBalancerTarget, INetworkLoadBalancerTarget, ILoadBalancerTarget, IConnectable
Syntax (vb)
Public MustInherit Class BaseService
Inherits Resource
Implements IBaseService, IService, IResource, IConstruct, IDependable, 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. |
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
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. |
ConfigureAwsVpcNetworking(IVpc, Nullable<Boolean>, ISubnetSelection, ISecurityGroup) | (deprecated) This method is called to create a networkConfiguration. |
ConfigureAwsVpcNetworkingWithSecurityGroups(IVpc, Nullable<Boolean>, ISubnetSelection, ISecurityGroup[]) | This method is called to create a networkConfiguration. |
EnableCloudMap(ICloudMapOptions) | Enable CloudMap service discovery for the 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
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
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
ConfigureAwsVpcNetworking(IVpc, Nullable<Boolean>, ISubnetSelection, ISecurityGroup)
(deprecated) This method is called to create a networkConfiguration.
protected virtual void ConfigureAwsVpcNetworking(IVpc vpc, Nullable<bool> assignPublicIp = null, ISubnetSelection vpcSubnets = null, ISecurityGroup securityGroup = null)
Parameters
- vpc IVpc
- assignPublicIp System.Nullable<System.Boolean>
- vpcSubnets ISubnetSelection
- securityGroup ISecurityGroup
Remarks
Stability: Deprecated
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
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
})
});