# Ec2ServiceAttributes

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

- Source: [`aws-ecs/lib/ec2/ec2-service.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-ecs/lib/ec2/ec2-service.ts#L119)
- Type last changed: v2.60.0 · 12 Jan 2023

## Example

TypeScript:

```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:

```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:

```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");
```

C# / .NET:

```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");
```

Golang:

```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

- `cluster`: [ICluster](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ICluster.html) (required) — The cluster that hosts the service.

- `serviceArn`: string — The service ARN.

  **Default:** either this, or `serviceName`, is required

- `serviceName`: string — The name of the service.

  **Default:** either this, or `serviceArn`, is required
