Class FargateService
java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.ecs.BaseService
software.amazon.awscdk.services.ecs.FargateService
- All Implemented Interfaces:
IResource,IConnectable,IBaseService,IFargateService,IService,ILoadBalancerTarget,IApplicationLoadBalancerTarget,INetworkLoadBalancerTarget,software.amazon.jsii.JsiiSerializable,software.constructs.IConstruct,software.constructs.IDependable
@Generated(value="jsii-pacmak/1.116.0 (build 0eddcff)",
date="2025-10-29T11:15:39.197Z")
@Stability(Stable)
public class FargateService
extends BaseService
implements IFargateService
This creates a service using the Fargate launch type on an ECS cluster.
Can also be used with Managed Instances compatible task definitions when using capacity provider strategies.
Example:
import software.amazon.awscdk.services.cloudwatch.*;
Cluster cluster;
TaskDefinition taskDefinition;
String serviceName = "MyFargateService";
FargateService service = FargateService.Builder.create(this, "Service")
.serviceName(serviceName)
.cluster(cluster)
.taskDefinition(taskDefinition)
.minHealthyPercent(100)
.build();
Metric cpuMetric = Metric.Builder.create()
.metricName("CPUUtilization")
.namespace("AWS/ECS")
.period(Duration.minutes(5))
.statistic("Average")
.dimensionsMap(Map.of(
"ClusterName", cluster.getClusterName(),
// Using `service.serviceName` here will cause a circular dependency
"ServiceName", serviceName))
.build();
Alarm myAlarm = Alarm.Builder.create(this, "CPUAlarm")
.alarmName("cpuAlarmName")
.metric(cpuMetric)
.evaluationPeriods(2)
.threshold(80)
.build();
service.enableDeploymentAlarms(List.of(myAlarm.getAlarmName()), DeploymentAlarmOptions.builder()
.behavior(AlarmBehavior.FAIL_ON_ALARM)
.build());
-
Nested Class Summary
Nested ClassesNested 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.constructs.IConstruct
software.constructs.IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.services.ecs.IFargateService
IFargateService.Jsii$Default, IFargateService.Jsii$ProxyNested 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.IResource
IResource.Jsii$Default -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFargateService(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protectedFargateService(software.amazon.jsii.JsiiObjectRef objRef) FargateService(software.constructs.Construct scope, String id, FargateServiceProps props) Constructs a new instance of the FargateService class. -
Method Summary
Modifier and TypeMethodDescriptionvoidattachToClassicLB(LoadBalancer loadBalancer) Registers the service as a target of a Classic Load Balancer (CLB).static IFargateServicefromFargateServiceArn(software.constructs.Construct scope, String id, String fargateServiceArn) Imports from the specified service ARN.static IBaseServicefromFargateServiceAttributes(software.constructs.Construct scope, String id, FargateServiceAttributes attrs) Imports from the specified service attributes.Methods inherited from class software.amazon.awscdk.services.ecs.BaseService
addLifecycleHook, addVolume, associateCloudMapService, attachToApplicationTargetGroup, attachToNetworkTargetGroup, autoScaleTaskCount, configureAwsVpcNetworkingWithSecurityGroups, configureAwsVpcNetworkingWithSecurityGroups, configureAwsVpcNetworkingWithSecurityGroups, configureAwsVpcNetworkingWithSecurityGroups, enableCloudMap, enableDeploymentAlarms, enableDeploymentAlarms, enableServiceConnect, enableServiceConnect, fromServiceArnWithCluster, getCloudmapService, getCloudMapService, getCluster, getConnections, getDeploymentAlarms, getLoadBalancers, getNetworkConfiguration, getServiceArn, getServiceName, getServiceRegistries, getTaskDefinition, isUsingECSDeploymentController, loadBalancerTarget, metric, metric, metricCpuUtilization, metricCpuUtilization, metricMemoryUtilization, metricMemoryUtilization, registerLoadBalancerTargets, setCloudmapService, setDeploymentAlarms, setLoadBalancers, setNetworkConfiguration, setServiceRegistriesMethods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResourceMethods inherited from class software.constructs.Construct
getNode, isConstruct, 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.constructs.IConstruct
getNodeMethods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getEnv, getStackMethods inherited from interface software.amazon.awscdk.services.ecs.IService
getServiceArn, getServiceNameMethods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Field Details
-
PROPERTY_INJECTION_ID
Uniquely identifies this class.
-
-
Constructor Details
-
FargateService
protected FargateService(software.amazon.jsii.JsiiObjectRef objRef) -
FargateService
protected FargateService(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
FargateService
@Stability(Stable) public FargateService(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull FargateServiceProps props) Constructs a new instance of the FargateService class.- Parameters:
scope- This parameter is required.id- This parameter is required.props- This parameter is required.
-
-
Method Details
-
fromFargateServiceArn
@Stability(Stable) @NotNull public static IFargateService fromFargateServiceArn(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String fargateServiceArn) Imports from the specified service ARN.- Parameters:
scope- This parameter is required.id- This parameter is required.fargateServiceArn- This parameter is required.
-
fromFargateServiceAttributes
@Stability(Stable) @NotNull public static IBaseService fromFargateServiceAttributes(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull FargateServiceAttributes attrs) Imports from the specified service attributes.- Parameters:
scope- This parameter is required.id- This parameter is required.attrs- 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- Overrides:
attachToClassicLBin classBaseService- Parameters:
loadBalancer- This parameter is required.
-