# ClusterAttributes

The properties to import from the ECS cluster.

Used as argument in: [Cluster.fromClusterAttributes](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.Cluster.html#fromclusterattributes)

- Source: [`aws-ecs/lib/cluster.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ecs/lib/cluster.ts#L1008)
- Type last changed: v2.85.0 · 21 Jun 2023

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_autoscaling as autoscaling } from 'aws-cdk-lib';
import { aws_ec2 as ec2 } from 'aws-cdk-lib';
import { aws_ecs as ecs } from 'aws-cdk-lib';
import { aws_kms as kms } from 'aws-cdk-lib';
import { aws_s3 as s3 } from 'aws-cdk-lib';
import { aws_servicediscovery as servicediscovery } from 'aws-cdk-lib';
import { aws_logs as interfaces_logs } from 'aws-cdk-lib/interfaces';

declare const autoScalingGroup: autoscaling.AutoScalingGroup;
declare const bucket: s3.Bucket;
declare const key: kms.Key;
declare const logGroupRef: interfaces_logs.ILogGroupRef;
declare const namespace: servicediscovery.INamespace;
declare const securityGroup: ec2.SecurityGroup;
declare const vpc: ec2.Vpc;
const clusterAttributes: ecs.ClusterAttributes = {
  clusterName: 'clusterName',
  vpc: vpc,

  // the properties below are optional
  autoscalingGroup: autoScalingGroup,
  clusterArn: 'clusterArn',
  defaultCloudMapNamespace: namespace,
  executeCommandConfiguration: {
    kmsKey: key,
    logConfiguration: {
      cloudWatchEncryptionEnabled: false,
      cloudWatchLogGroup: logGroupRef,
      s3Bucket: bucket,
      s3EncryptionEnabled: false,
      s3KeyPrefix: 's3KeyPrefix',
    },
    logging: ecs.ExecuteCommandLogging.NONE,
  },
  hasEc2Capacity: false,
  securityGroups: [securityGroup],
};
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_autoscaling as autoscaling
from aws_cdk import aws_ec2 as ec2
from aws_cdk import aws_ecs as ecs
from aws_cdk import aws_kms as kms
from aws_cdk import aws_s3 as s3
from aws_cdk import aws_servicediscovery as servicediscovery
from aws_cdk.interfaces import aws_logs as interfaces_logs

# auto_scaling_group: autoscaling.AutoScalingGroup
# bucket: s3.Bucket
# key: kms.Key
# log_group_ref: interfaces_logs.ILogGroupRef
# namespace: servicediscovery.INamespace
# security_group: ec2.SecurityGroup
# vpc: ec2.Vpc

cluster_attributes = ecs.ClusterAttributes(
    cluster_name="clusterName",
    vpc=vpc,

    # the properties below are optional
    autoscaling_group=auto_scaling_group,
    cluster_arn="clusterArn",
    default_cloud_map_namespace=namespace,
    execute_command_configuration=ecs.ExecuteCommandConfiguration(
        kms_key=key,
        log_configuration=ecs.ExecuteCommandLogConfiguration(
            cloud_watch_encryption_enabled=False,
            cloud_watch_log_group=log_group_ref,
            s3_bucket=bucket,
            s3_encryption_enabled=False,
            s3_key_prefix="s3KeyPrefix"
        ),
        logging=ecs.ExecuteCommandLogging.NONE
    ),
    has_ec2_capacity=False,
    security_groups=[security_group]
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.autoscaling.*;
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.ecs.*;
import software.amazon.awscdk.services.kms.*;
import software.amazon.awscdk.services.s3.*;
import software.amazon.awscdk.services.servicediscovery.*;
import software.amazon.awscdk.interfaces.logs.*;

AutoScalingGroup autoScalingGroup;
Bucket bucket;
Key key;
ILogGroupRef logGroupRef;
INamespace namespace;
SecurityGroup securityGroup;
Vpc vpc;

ClusterAttributes clusterAttributes = ClusterAttributes.builder()
        .clusterName("clusterName")
        .vpc(vpc)

        // the properties below are optional
        .autoscalingGroup(autoScalingGroup)
        .clusterArn("clusterArn")
        .defaultCloudMapNamespace(namespace)
        .executeCommandConfiguration(ExecuteCommandConfiguration.builder()
                .kmsKey(key)
                .logConfiguration(ExecuteCommandLogConfiguration.builder()
                        .cloudWatchEncryptionEnabled(false)
                        .cloudWatchLogGroup(logGroupRef)
                        .s3Bucket(bucket)
                        .s3EncryptionEnabled(false)
                        .s3KeyPrefix("s3KeyPrefix")
                        .build())
                .logging(ExecuteCommandLogging.NONE)
                .build())
        .hasEc2Capacity(false)
        .securityGroups(List.of(securityGroup))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.AutoScaling;
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.ECS;
using Amazon.CDK.AWS.KMS;
using Amazon.CDK.AWS.S3;
using Amazon.CDK.AWS.ServiceDiscovery;
using Amazon.CDK.Interfaces.Logs;

AutoScalingGroup autoScalingGroup;
Bucket bucket;
Key key;
ILogGroupRef logGroupRef;
INamespace namespace;
SecurityGroup securityGroup;
Vpc vpc;

var clusterAttributes = new ClusterAttributes {
    ClusterName = "clusterName",
    Vpc = vpc,

    // the properties below are optional
    AutoscalingGroup = autoScalingGroup,
    ClusterArn = "clusterArn",
    DefaultCloudMapNamespace = namespace,
    ExecuteCommandConfiguration = new ExecuteCommandConfiguration {
        KmsKey = key,
        LogConfiguration = new ExecuteCommandLogConfiguration {
            CloudWatchEncryptionEnabled = false,
            CloudWatchLogGroup = logGroupRef,
            S3Bucket = bucket,
            S3EncryptionEnabled = false,
            S3KeyPrefix = "s3KeyPrefix"
        },
        Logging = ExecuteCommandLogging.NONE
    },
    HasEc2Capacity = false,
    SecurityGroups = new [] { securityGroup }
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var autoScalingGroup AutoScalingGroup
var bucket Bucket
var key Key
var logGroupRef ILogGroupRef
var namespace INamespace
var securityGroup SecurityGroup
var vpc Vpc

clusterAttributes := &ClusterAttributes{
	ClusterName: jsii.String("clusterName"),
	Vpc: vpc,

	// the properties below are optional
	AutoscalingGroup: autoScalingGroup,
	ClusterArn: jsii.String("clusterArn"),
	DefaultCloudMapNamespace: namespace,
	ExecuteCommandConfiguration: &ExecuteCommandConfiguration{
		KmsKey: key,
		LogConfiguration: &ExecuteCommandLogConfiguration{
			CloudWatchEncryptionEnabled: jsii.Boolean(false),
			CloudWatchLogGroup: logGroupRef,
			S3Bucket: bucket,
			S3EncryptionEnabled: jsii.Boolean(false),
			S3KeyPrefix: jsii.String("s3KeyPrefix"),
		},
		Logging: awscdk.Aws_ecs.ExecuteCommandLogging_NONE,
	},
	HasEc2Capacity: jsii.Boolean(false),
	SecurityGroups: []ISecurityGroup{
		securityGroup,
	},
}
```

## Properties

- `autoscalingGroup`: [IAutoScalingGroup](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.IAutoScalingGroup.html) — Autoscaling group added to the cluster if capacity is added.

  **Default:** No default autoscaling group

- `clusterArn`: string — The Amazon Resource Name (ARN) that identifies the cluster.

  **Default:** Derived from clusterName

- `clusterName`: string (required) — The name of the cluster.

- `defaultCloudMapNamespace`: [INamespace](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_servicediscovery.INamespace.html) — The AWS Cloud Map namespace to associate with the cluster.

  **Default:** No default namespace

- `executeCommandConfiguration`: [ExecuteCommandConfiguration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ExecuteCommandConfiguration.html) = none. — The execute command configuration for the cluster.

- `hasEc2Capacity`: boolean = true — Specifies whether the cluster has EC2 instance capacity.

- `securityGroups`: [ISecurityGroup](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html)[] — The security groups associated with the container instances registered to the cluster.

  **Default:** no security groups

- `vpc`: [IVpc](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) (required) — The VPC associated with the cluster.
