Class Ec2Service

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
All Implemented Interfaces:
IConstruct, IDependable, IResource, IConnectable, IBaseService, IEc2Service, IService, ILoadBalancerTarget, IApplicationLoadBalancerTarget, INetworkLoadBalancerTarget, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:30:47.288Z") @Stability(Stable) public class Ec2Service extends BaseService implements IEc2Service
This creates a service using the EC2 launch type on an ECS cluster.

Example:

 Cluster cluster;
 TaskDefinition taskDefinition;
 Vpc vpc;
 Ec2Service service = Ec2Service.Builder.create(this, "Service").cluster(cluster).taskDefinition(taskDefinition).build();
 LoadBalancer lb = LoadBalancer.Builder.create(this, "LB").vpc(vpc).build();
 lb.addListener(LoadBalancerListener.builder().externalPort(80).build());
 lb.addTarget(service.loadBalancerTarget(LoadBalancerTargetOptions.builder()
         .containerName("MyContainer")
         .containerPort(80)
         .build()));
 
  • Constructor Details

    • Ec2Service

      protected Ec2Service(software.amazon.jsii.JsiiObjectRef objRef)
    • Ec2Service

      protected Ec2Service(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • Ec2Service

      @Stability(Stable) public Ec2Service(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull Ec2ServiceProps props)
      Constructs a new instance of the Ec2Service class.

      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • fromEc2ServiceArn

      @Stability(Stable) @NotNull public static IEc2Service fromEc2ServiceArn(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String ec2ServiceArn)
      Imports from the specified service ARN.

      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      ec2ServiceArn - This parameter is required.
    • fromEc2ServiceAttributes

      @Stability(Stable) @NotNull public static IBaseService fromEc2ServiceAttributes(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull Ec2ServiceAttributes attrs)
      Imports from the specified service attributes.

      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      attrs - This parameter is required.
    • addPlacementConstraints

      @Stability(Stable) public void addPlacementConstraints(@NotNull @NotNull PlacementConstraint... constraints)
      Adds one or more placement constraints to use for tasks in the service.

      For more information, see Amazon ECS Task Placement Constraints.

      Parameters:
      constraints - This parameter is required.
    • addPlacementStrategies

      @Stability(Stable) public void addPlacementStrategies(@NotNull @NotNull PlacementStrategy... strategies)
      Adds one or more placement strategies to use for tasks in the service.

      For more information, see Amazon ECS Task Placement Strategies.

      Parameters:
      strategies - This parameter is required.
    • validate

      @Stability(Stable) @NotNull protected List<String> validate()
      Validates this Ec2Service.
      Overrides:
      validate in class Construct
      Returns:
      An array of validation error messages, or an empty array if the construct is valid.