Skip to content
v2.277.0

Ec2ServiceAttributes Struct ​

The properties to import from the service using the EC2 launch type.

Example ​

ts
declare const cluster: ecs.Cluster;

// Import service from EC2 service attributes
const ec2ServiceFromAttributes = ecs.Ec2Service.fromEc2ServiceAttributes(this, 'Ec2ServiceFromAttributes', {
  serviceArn: 'arn:aws:ecs:us-west-2:123456789012:service/my-http-service',
  cluster,
});

// Import service from EC2 service ARN
const ec2ServiceFromArn = ecs.Ec2Service.fromEc2ServiceArn(this, 'Ec2ServiceFromArn', 'arn:aws:ecs:us-west-2:123456789012:service/my-http-service');

// Import service from Fargate service attributes
const fargateServiceFromAttributes = ecs.FargateService.fromFargateServiceAttributes(this, 'FargateServiceFromAttributes', {
  serviceArn: 'arn:aws:ecs:us-west-2:123456789012:service/my-http-service',
  cluster,
});

// Import service from Fargate service ARN
const fargateServiceFromArn = ecs.FargateService.fromFargateServiceArn(this, 'FargateServiceFromArn', 'arn:aws:ecs:us-west-2:123456789012:service/my-http-service');
python
# cluster: ecs.Cluster


# Import service from EC2 service attributes
ec2_service_from_attributes = ecs.Ec2Service.from_ec2_service_attributes(self, "Ec2ServiceFromAttributes",
    service_arn="arn:aws:ecs:us-west-2:123456789012:service/my-http-service",
    cluster=cluster
)

# Import service from EC2 service ARN
ec2_service_from_arn = ecs.Ec2Service.from_ec2_service_arn(self, "Ec2ServiceFromArn", "arn:aws:ecs:us-west-2:123456789012:service/my-http-service")

# Import service from Fargate service attributes
fargate_service_from_attributes = ecs.FargateService.from_fargate_service_attributes(self, "FargateServiceFromAttributes",
    service_arn="arn:aws:ecs:us-west-2:123456789012:service/my-http-service",
    cluster=cluster
)

# Import service from Fargate service ARN
fargate_service_from_arn = ecs.FargateService.from_fargate_service_arn(self, "FargateServiceFromArn", "arn:aws:ecs:us-west-2:123456789012:service/my-http-service")
java
Cluster cluster;


// Import service from EC2 service attributes
IBaseService ec2ServiceFromAttributes = Ec2Service.fromEc2ServiceAttributes(this, "Ec2ServiceFromAttributes", Ec2ServiceAttributes.builder()
        .serviceArn("arn:aws:ecs:us-west-2:123456789012:service/my-http-service")
        .cluster(cluster)
        .build());

// Import service from EC2 service ARN
IEc2Service ec2ServiceFromArn = Ec2Service.fromEc2ServiceArn(this, "Ec2ServiceFromArn", "arn:aws:ecs:us-west-2:123456789012:service/my-http-service");

// Import service from Fargate service attributes
IBaseService fargateServiceFromAttributes = FargateService.fromFargateServiceAttributes(this, "FargateServiceFromAttributes", FargateServiceAttributes.builder()
        .serviceArn("arn:aws:ecs:us-west-2:123456789012:service/my-http-service")
        .cluster(cluster)
        .build());

// Import service from Fargate service ARN
IFargateService fargateServiceFromArn = FargateService.fromFargateServiceArn(this, "FargateServiceFromArn", "arn:aws:ecs:us-west-2:123456789012:service/my-http-service");
csharp
// Install: dotnet add package Amazon.CDK.Lib
Cluster cluster;


// Import service from EC2 service attributes
var ec2ServiceFromAttributes = Ec2Service.FromEc2ServiceAttributes(this, "Ec2ServiceFromAttributes", new Ec2ServiceAttributes {
    ServiceArn = "arn:aws:ecs:us-west-2:123456789012:service/my-http-service",
    Cluster = cluster
});

// Import service from EC2 service ARN
var ec2ServiceFromArn = Ec2Service.FromEc2ServiceArn(this, "Ec2ServiceFromArn", "arn:aws:ecs:us-west-2:123456789012:service/my-http-service");

// Import service from Fargate service attributes
var fargateServiceFromAttributes = FargateService.FromFargateServiceAttributes(this, "FargateServiceFromAttributes", new FargateServiceAttributes {
    ServiceArn = "arn:aws:ecs:us-west-2:123456789012:service/my-http-service",
    Cluster = cluster
});

// Import service from Fargate service ARN
var fargateServiceFromArn = FargateService.FromFargateServiceArn(this, "FargateServiceFromArn", "arn:aws:ecs:us-west-2:123456789012:service/my-http-service");
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var cluster Cluster


// Import service from EC2 service attributes
ec2ServiceFromAttributes := ecs.Ec2Service_FromEc2ServiceAttributes(this, jsii.String("Ec2ServiceFromAttributes"), &Ec2ServiceAttributes{
	ServiceArn: jsii.String("arn:aws:ecs:us-west-2:123456789012:service/my-http-service"),
	Cluster: Cluster,
})

// Import service from EC2 service ARN
ec2ServiceFromArn := ecs.Ec2Service_FromEc2ServiceArn(this, jsii.String("Ec2ServiceFromArn"), jsii.String("arn:aws:ecs:us-west-2:123456789012:service/my-http-service"))

// Import service from Fargate service attributes
fargateServiceFromAttributes := ecs.FargateService_FromFargateServiceAttributes(this, jsii.String("FargateServiceFromAttributes"), &FargateServiceAttributes{
	ServiceArn: jsii.String("arn:aws:ecs:us-west-2:123456789012:service/my-http-service"),
	Cluster: Cluster,
})

// Import service from Fargate service ARN
fargateServiceFromArn := ecs.FargateService_FromFargateServiceArn(this, jsii.String("FargateServiceFromArn"), jsii.String("arn:aws:ecs:us-west-2:123456789012:service/my-http-service"))

Properties ​

clusterIClusterclusterIClusterclusterIClusterClusterIClusterClusterICluster required #
The cluster that hosts the service.
serviceArnoptionalstringservice_arnoptionalstrserviceArnoptionalStringServiceArnoptionalstringServiceArnoptional*string #
The service ARN.

Default: either this, or serviceName, is required

serviceNameoptionalstringservice_nameoptionalstrserviceNameoptionalStringServiceNameoptionalstringServiceNameoptional*string #
The name of the service.

Default: either this, or serviceArn, is required