Class BaseService
- All Implemented Interfaces:
IResource
,IConnectable
,IBaseService
,IService
,ILoadBalancerTarget
,IApplicationLoadBalancerTarget
,INetworkLoadBalancerTarget
,software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
,software.constructs.IDependable
- Direct Known Subclasses:
Ec2Service
,ExternalService
,FargateService
Example:
import software.amazon.awscdk.services.ecs.*; IBaseService service = BaseService.fromServiceArnWithCluster(this, "EcsService", "arn:aws:ecs:us-east-1:123456789012:service/myClusterName/myServiceName"); Pipeline pipeline = new Pipeline(this, "MyPipeline"); Artifact buildOutput = new Artifact(); // add source and build stages to the pipeline as usual... IStage deployStage = pipeline.addStage(StageOptions.builder() .stageName("Deploy") .actions(List.of( EcsDeployAction.Builder.create() .actionName("DeployAction") .service(service) .input(buildOutput) .build())) .build());
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.IApplicationLoadBalancerTarget
IApplicationLoadBalancerTarget.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.ecs.IBaseService
IBaseService.Jsii$Default
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancing.ILoadBalancerTarget
ILoadBalancerTarget.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.INetworkLoadBalancerTarget
INetworkLoadBalancerTarget.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$Default
-
Constructor Summary
ModifierConstructorDescriptionprotected
BaseService
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
BaseService
(software.amazon.jsii.JsiiObjectRef objRef) protected
BaseService
(software.constructs.Construct scope, String id, BaseServiceProps props, Object additionalProps, TaskDefinition taskDefinition) Constructs a new instance of the BaseService class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addVolume
(ServiceManagedVolume volume) Adds a volume to the Service.void
Associates this service with a CloudMap service.attachToApplicationTargetGroup
(IApplicationTargetGroup targetGroup) This method is called to attach this service to an Application Load Balancer.void
attachToClassicLB
(LoadBalancer loadBalancer) Registers the service as a target of a Classic Load Balancer (CLB).attachToNetworkTargetGroup
(INetworkTargetGroup targetGroup) This method is called to attach this service to a Network Load Balancer.An attribute representing the minimum and maximum task count for an AutoScalingGroup.protected void
This method is called to create a networkConfiguration.protected void
configureAwsVpcNetworkingWithSecurityGroups
(IVpc vpc, Boolean assignPublicIp) This method is called to create a networkConfiguration.protected void
configureAwsVpcNetworkingWithSecurityGroups
(IVpc vpc, Boolean assignPublicIp, SubnetSelection vpcSubnets) This method is called to create a networkConfiguration.protected void
configureAwsVpcNetworkingWithSecurityGroups
(IVpc vpc, Boolean assignPublicIp, SubnetSelection vpcSubnets, List<ISecurityGroup> securityGroups) This method is called to create a networkConfiguration.enableCloudMap
(CloudMapOptions options) Enable CloudMap service discovery for the service.void
enableDeploymentAlarms
(List<String> alarmNames) Enable Deployment Alarms which take advantage of arbitrary alarms and configure them after service initialization.void
enableDeploymentAlarms
(List<String> alarmNames, DeploymentAlarmOptions options) Enable Deployment Alarms which take advantage of arbitrary alarms and configure them after service initialization.void
Enable Service Connect on this service.void
Enable Service Connect on this service.static IBaseService
fromServiceArnWithCluster
(software.constructs.Construct scope, String id, String serviceArn) Import an existing ECS/Fargate Service using the service cluster format.protected Service
The details of the AWS Cloud Map service.The CloudMap service created for this service, if any.The cluster that hosts the service.The security groups which manage the allowed network traffic for the service.protected CfnService.DeploymentAlarmsProperty
The deployment alarms property - this will be rendered directly and lazily as the CfnService.alarms property.protected List<CfnService.LoadBalancerProperty>
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 CfnService.NetworkConfigurationProperty
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.The Amazon Resource Name (ARN) of the service.The name of the service.protected List<CfnService.ServiceRegistryProperty>
The details of the service discovery registries to assign to this service.The task definition to use for tasks in the service.Return a load balancing target for a specific container and port.This method returns the specified CloudWatch metric name for this service.metric
(String metricName, MetricOptions props) This method returns the specified CloudWatch metric name for this service.This method returns the CloudWatch metric for this service's CPU utilization.This method returns the CloudWatch metric for this service's CPU utilization.This method returns the CloudWatch metric for this service's memory utilization.This method returns the CloudWatch metric for this service's memory utilization.void
registerLoadBalancerTargets
(@NotNull EcsTarget... targets) 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.protected void
setCloudmapService
(Service value) The details of the AWS Cloud Map service.protected void
The deployment alarms property - this will be rendered directly and lazily as the CfnService.alarms property.protected void
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 void
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 void
The details of the service discovery registries to assign to this service.Methods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResource
Methods inherited from class software.constructs.Construct
getNode, isConstruct, toString
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.constructs.IConstruct
getNode
Methods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getEnv, getStack
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
BaseService
protected BaseService(software.amazon.jsii.JsiiObjectRef objRef) -
BaseService
protected BaseService(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
BaseService
@Stability(Stable) protected BaseService(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull BaseServiceProps props, @NotNull Object additionalProps, @NotNull TaskDefinition taskDefinition) Constructs a new instance of the BaseService class.- Parameters:
scope
- This parameter is required.id
- This parameter is required.props
- This parameter is required.additionalProps
- This parameter is required.taskDefinition
- This parameter is required.
-
-
Method Details
-
fromServiceArnWithCluster
@Stability(Stable) @NotNull public static IBaseService fromServiceArnWithCluster(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String serviceArn) Import an existing ECS/Fargate Service using the service cluster format.The format is the "new" format "arn:aws:ecs:region:aws_account_id:service/cluster-name/service-name".
- Parameters:
scope
- This parameter is required.id
- This parameter is required.serviceArn
- This parameter is required.- See Also:
-
addVolume
Adds a volume to the Service.- Parameters:
volume
- This parameter is required.
-
associateCloudMapService
@Stability(Stable) public void associateCloudMapService(@NotNull AssociateCloudMapServiceOptions options) Associates this service with a CloudMap service.- Parameters:
options
- This parameter is required.
-
attachToApplicationTargetGroup
@Stability(Stable) @NotNull public LoadBalancerTargetProps attachToApplicationTargetGroup(@NotNull IApplicationTargetGroup targetGroup) This method is called to attach this service to an Application Load Balancer.Don't call this function directly. Instead, call
listener.addTargets()
to add this service to a load balancer.- Specified by:
attachToApplicationTargetGroup
in interfaceIApplicationLoadBalancerTarget
- Parameters:
targetGroup
- This parameter is required.
-
attachToClassicLB
Registers the service as a target of a Classic Load Balancer (CLB).Don't call this. Call
loadBalancer.addTarget()
instead.- Specified by:
attachToClassicLB
in interfaceILoadBalancerTarget
- Parameters:
loadBalancer
- This parameter is required.
-
attachToNetworkTargetGroup
@Stability(Stable) @NotNull public LoadBalancerTargetProps attachToNetworkTargetGroup(@NotNull INetworkTargetGroup targetGroup) This method is called to attach this service to a Network Load Balancer.Don't call this function directly. Instead, call
listener.addTargets()
to add this service to a load balancer.- Specified by:
attachToNetworkTargetGroup
in interfaceINetworkLoadBalancerTarget
- Parameters:
targetGroup
- This parameter is required.
-
autoScaleTaskCount
@Stability(Stable) @NotNull public ScalableTaskCount autoScaleTaskCount(@NotNull EnableScalingProps props) An attribute representing the minimum and maximum task count for an AutoScalingGroup.- Parameters:
props
- This parameter is required.
-
configureAwsVpcNetworkingWithSecurityGroups
@Stability(Stable) protected void configureAwsVpcNetworkingWithSecurityGroups(@NotNull IVpc vpc, @Nullable Boolean assignPublicIp, @Nullable SubnetSelection vpcSubnets, @Nullable List<ISecurityGroup> securityGroups) This method is called to create a networkConfiguration.- Parameters:
vpc
- This parameter is required.assignPublicIp
-vpcSubnets
-securityGroups
-
-
configureAwsVpcNetworkingWithSecurityGroups
@Stability(Stable) protected void configureAwsVpcNetworkingWithSecurityGroups(@NotNull IVpc vpc, @Nullable Boolean assignPublicIp, @Nullable SubnetSelection vpcSubnets) This method is called to create a networkConfiguration.- Parameters:
vpc
- This parameter is required.assignPublicIp
-vpcSubnets
-
-
configureAwsVpcNetworkingWithSecurityGroups
@Stability(Stable) protected void configureAwsVpcNetworkingWithSecurityGroups(@NotNull IVpc vpc, @Nullable Boolean assignPublicIp) This method is called to create a networkConfiguration.- Parameters:
vpc
- This parameter is required.assignPublicIp
-
-
configureAwsVpcNetworkingWithSecurityGroups
This method is called to create a networkConfiguration.- Parameters:
vpc
- This parameter is required.
-
enableCloudMap
Enable CloudMap service discovery for the service.- Parameters:
options
- This parameter is required.- Returns:
- The created CloudMap service
-
enableDeploymentAlarms
@Stability(Stable) public void enableDeploymentAlarms(@NotNull List<String> alarmNames, @Nullable DeploymentAlarmOptions options) Enable Deployment Alarms which take advantage of arbitrary alarms and configure them after service initialization.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.- Parameters:
alarmNames
- This parameter is required.options
-
-
enableDeploymentAlarms
Enable Deployment Alarms which take advantage of arbitrary alarms and configure them after service initialization.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.- Parameters:
alarmNames
- This parameter is required.
-
enableServiceConnect
Enable Service Connect on this service.- Parameters:
config
-
-
enableServiceConnect
@Stability(Stable) public void enableServiceConnect()Enable Service Connect on this service. -
loadBalancerTarget
@Stability(Stable) @NotNull public IEcsLoadBalancerTarget loadBalancerTarget(@NotNull LoadBalancerTargetOptions options) Return a load balancing target for a specific container and port.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.Example:
ApplicationListener listener; BaseService service; listener.addTargets("ECS", AddApplicationTargetsProps.builder() .port(80) .targets(List.of(service.loadBalancerTarget(LoadBalancerTargetOptions.builder() .containerName("MyContainer") .containerPort(1234) .build()))) .build());
- Parameters:
options
- This parameter is required.
-
metric
@Stability(Stable) @NotNull public Metric metric(@NotNull String metricName, @Nullable MetricOptions props) This method returns the specified CloudWatch metric name for this service.- Parameters:
metricName
- This parameter is required.props
-
-
metric
This method returns the specified CloudWatch metric name for this service.- Parameters:
metricName
- This parameter is required.
-
metricCpuUtilization
This method returns the CloudWatch metric for this service's CPU utilization.Default: average over 5 minutes
- Parameters:
props
-
-
metricCpuUtilization
This method returns the CloudWatch metric for this service's CPU utilization.Default: average over 5 minutes
-
metricMemoryUtilization
This method returns the CloudWatch metric for this service's memory utilization.Default: average over 5 minutes
- Parameters:
props
-
-
metricMemoryUtilization
This method returns the CloudWatch metric for this service's memory utilization.Default: average over 5 minutes
-
registerLoadBalancerTargets
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.Alternatively, you can use
listener.addTargets()
to create targets and add them to target groups.Example:
ApplicationListener listener; BaseService service; service.registerLoadBalancerTargets(EcsTarget.builder() .containerName("web") .containerPort(80) .newTargetGroupId("ECS") .listener(ListenerConfig.applicationListener(listener, AddApplicationTargetsProps.builder() .protocol(ApplicationProtocol.HTTPS) .build())) .build());
- Parameters:
targets
- This parameter is required.
-
getCluster
The cluster that hosts the service.- Specified by:
getCluster
in interfaceIBaseService
-
getConnections
The security groups which manage the allowed network traffic for the service.- Specified by:
getConnections
in interfaceIConnectable
-
getServiceArn
The Amazon Resource Name (ARN) of the service.- Specified by:
getServiceArn
in interfaceIService
-
getServiceName
The name of the service.- Specified by:
getServiceName
in interfaceIService
-
getTaskDefinition
The task definition to use for tasks in the service. -
getCloudMapService
The CloudMap service created for this service, if any. -
getLoadBalancers
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. -
setLoadBalancers
@Stability(Stable) protected void setLoadBalancers(@NotNull List<CfnService.LoadBalancerProperty> value) 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. -
getServiceRegistries
@Stability(Stable) @NotNull protected List<CfnService.ServiceRegistryProperty> getServiceRegistries()The details of the service discovery registries to assign to this service.For more information, see Service Discovery.
-
setServiceRegistries
@Stability(Stable) protected void setServiceRegistries(@NotNull List<CfnService.ServiceRegistryProperty> value) The details of the service discovery registries to assign to this service.For more information, see Service Discovery.
-
getCloudmapService
The details of the AWS Cloud Map service. -
setCloudmapService
The details of the AWS Cloud Map service. -
getDeploymentAlarms
The deployment alarms property - this will be rendered directly and lazily as the CfnService.alarms property. -
setDeploymentAlarms
@Stability(Stable) protected void setDeploymentAlarms(@Nullable CfnService.DeploymentAlarmsProperty value) The deployment alarms property - this will be rendered directly and lazily as the CfnService.alarms property. -
getNetworkConfiguration
@Stability(Stable) @Nullable protected CfnService.NetworkConfigurationProperty getNetworkConfiguration()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. -
setNetworkConfiguration
@Stability(Stable) protected void setNetworkConfiguration(@Nullable CfnService.NetworkConfigurationProperty value) 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.
-