Class BaseService
- All Implemented Interfaces:
IConstruct,IDependable,IResource,IConnectable,IBaseService,IService,ILoadBalancerTarget,IApplicationLoadBalancerTarget,INetworkLoadBalancerTarget,software.amazon.jsii.JsiiSerializable,software.constructs.IConstruct
- 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.constructs.Construct
software.constructs.Construct.BuilderNested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationModeNested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.IApplicationLoadBalancerTarget
IApplicationLoadBalancerTarget.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.services.ecs.IBaseService
IBaseService.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.core.IConstruct
IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancing.ILoadBalancerTarget
ILoadBalancerTarget.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.INetworkLoadBalancerTarget
INetworkLoadBalancerTarget.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.core.IResource
IResource.Jsii$Default -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseService(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protectedBaseService(software.amazon.jsii.JsiiObjectRef objRef) protectedBaseService(software.constructs.Construct scope, String id, BaseServiceProps props, Object additionalProps, TaskDefinition taskDefinition) Constructs a new instance of the BaseService class. -
Method Summary
Modifier and TypeMethodDescriptionvoidAssociates this service with a CloudMap service.attachToApplicationTargetGroup(IApplicationTargetGroup targetGroup) This method is called to attach this service to an Application Load Balancer.voidattachToClassicLB(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 voidDeprecated.use configureAwsVpcNetworkingWithSecurityGroups instead.protected voidconfigureAwsVpcNetworking(IVpc vpc, Boolean assignPublicIp) Deprecated.use configureAwsVpcNetworkingWithSecurityGroups instead.protected voidconfigureAwsVpcNetworking(IVpc vpc, Boolean assignPublicIp, SubnetSelection vpcSubnets) Deprecated.use configureAwsVpcNetworkingWithSecurityGroups instead.protected voidconfigureAwsVpcNetworking(IVpc vpc, Boolean assignPublicIp, SubnetSelection vpcSubnets, ISecurityGroup securityGroup) Deprecated.use configureAwsVpcNetworkingWithSecurityGroups instead.protected voidThis method is called to create a networkConfiguration.protected voidconfigureAwsVpcNetworkingWithSecurityGroups(IVpc vpc, Boolean assignPublicIp) This method is called to create a networkConfiguration.protected voidconfigureAwsVpcNetworkingWithSecurityGroups(IVpc vpc, Boolean assignPublicIp, SubnetSelection vpcSubnets) This method is called to create a networkConfiguration.protected voidconfigureAwsVpcNetworkingWithSecurityGroups(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.static IBaseServicefromServiceArnWithCluster(software.constructs.Construct scope, String id, String serviceArn) Import an existing ECS/Fargate Service using the service cluster format.protected ServiceThe 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 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.NetworkConfigurationPropertyA 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.voidregisterLoadBalancerTargets(@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 voidsetCloudmapService(Service value) The details of the AWS Cloud Map service.protected voidA 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 voidA 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 voidThe details of the service discovery registries to assign to this service.Methods inherited from class software.amazon.awscdk.core.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isResourceMethods inherited from class software.amazon.awscdk.core.Construct
getNode, isConstruct, onPrepare, onSynthesize, onValidate, prepare, synthesize, validateMethods inherited from class software.constructs.Construct
toStringMethods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface software.amazon.awscdk.core.IConstruct
getNodeMethods inherited from interface software.amazon.awscdk.core.IResource
applyRemovalPolicy, getEnv, getStackMethods 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:
-
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:
attachToApplicationTargetGroupin 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:
attachToClassicLBin 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:
attachToNetworkTargetGroupin 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.
-
configureAwsVpcNetworking
@Stability(Deprecated) @Deprecated protected void configureAwsVpcNetworking(@NotNull IVpc vpc, @Nullable Boolean assignPublicIp, @Nullable SubnetSelection vpcSubnets, @Nullable ISecurityGroup securityGroup) Deprecated.use configureAwsVpcNetworkingWithSecurityGroups instead.(deprecated) This method is called to create a networkConfiguration.- Parameters:
vpc- This parameter is required.assignPublicIp-vpcSubnets-securityGroup-
-
configureAwsVpcNetworking
@Stability(Deprecated) @Deprecated protected void configureAwsVpcNetworking(@NotNull IVpc vpc, @Nullable Boolean assignPublicIp, @Nullable SubnetSelection vpcSubnets) Deprecated.use configureAwsVpcNetworkingWithSecurityGroups instead.(deprecated) This method is called to create a networkConfiguration.- Parameters:
vpc- This parameter is required.assignPublicIp-vpcSubnets-
-
configureAwsVpcNetworking
@Stability(Deprecated) @Deprecated protected void configureAwsVpcNetworking(@NotNull IVpc vpc, @Nullable Boolean assignPublicIp) Deprecated.use configureAwsVpcNetworkingWithSecurityGroups instead.(deprecated) This method is called to create a networkConfiguration.- Parameters:
vpc- This parameter is required.assignPublicIp-
-
configureAwsVpcNetworking
Deprecated.use configureAwsVpcNetworkingWithSecurityGroups instead.(deprecated) This method is called to create a networkConfiguration.- Parameters:
vpc- 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
-
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
Serviceobject 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:
getClusterin interfaceIBaseService
-
getConnections
The security groups which manage the allowed network traffic for the service.- Specified by:
getConnectionsin interfaceIConnectable
-
getServiceArn
The Amazon Resource Name (ARN) of the service.- Specified by:
getServiceArnin interfaceIService
-
getServiceName
The name of the service.- Specified by:
getServiceNamein 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. -
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.
-