# ExecuteCommandLogging

The log settings to use to for logging the execute command session.

For more information, see
[Logging] https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-cluster-executecommandconfiguration.html#cfn-ecs-cluster-executecommandconfiguration-logging

- 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#L1370)

## Example

TypeScript:

```ts
declare const vpc: ec2.Vpc;
const kmsKey = new kms.Key(this, 'KmsKey');

// Pass the KMS key in the `encryptionKey` field to associate the key to the log group
const logGroup = new logs.LogGroup(this, 'LogGroup', {
  encryptionKey: kmsKey,
});

// Pass the KMS key in the `encryptionKey` field to associate the key to the S3 bucket
const execBucket = new s3.Bucket(this, 'EcsExecBucket', {
  encryptionKey: kmsKey,
});

const cluster = new ecs.Cluster(this, 'Cluster', {
  vpc,
  executeCommandConfiguration: {
    kmsKey,
    logConfiguration: {
      cloudWatchLogGroup: logGroup,
      cloudWatchEncryptionEnabled: true,
      s3Bucket: execBucket,
      s3EncryptionEnabled: true,
      s3KeyPrefix: 'exec-command-output',
    },
    logging: ecs.ExecuteCommandLogging.OVERRIDE,
  },
});
```

Python:

```python
# vpc: ec2.Vpc

kms_key = kms.Key(self, "KmsKey")

# Pass the KMS key in the `encryptionKey` field to associate the key to the log group
log_group = logs.LogGroup(self, "LogGroup",
    encryption_key=kms_key
)

# Pass the KMS key in the `encryptionKey` field to associate the key to the S3 bucket
exec_bucket = s3.Bucket(self, "EcsExecBucket",
    encryption_key=kms_key
)

cluster = ecs.Cluster(self, "Cluster",
    vpc=vpc,
    execute_command_configuration=ecs.ExecuteCommandConfiguration(
        kms_key=kms_key,
        log_configuration=ecs.ExecuteCommandLogConfiguration(
            cloud_watch_log_group=log_group,
            cloud_watch_encryption_enabled=True,
            s3_bucket=exec_bucket,
            s3_encryption_enabled=True,
            s3_key_prefix="exec-command-output"
        ),
        logging=ecs.ExecuteCommandLogging.OVERRIDE
    )
)
```

Java:

```java
Vpc vpc;

Key kmsKey = new Key(this, "KmsKey");

// Pass the KMS key in the `encryptionKey` field to associate the key to the log group
LogGroup logGroup = LogGroup.Builder.create(this, "LogGroup")
        .encryptionKey(kmsKey)
        .build();

// Pass the KMS key in the `encryptionKey` field to associate the key to the S3 bucket
Bucket execBucket = Bucket.Builder.create(this, "EcsExecBucket")
        .encryptionKey(kmsKey)
        .build();

Cluster cluster = Cluster.Builder.create(this, "Cluster")
        .vpc(vpc)
        .executeCommandConfiguration(ExecuteCommandConfiguration.builder()
                .kmsKey(kmsKey)
                .logConfiguration(ExecuteCommandLogConfiguration.builder()
                        .cloudWatchLogGroup(logGroup)
                        .cloudWatchEncryptionEnabled(true)
                        .s3Bucket(execBucket)
                        .s3EncryptionEnabled(true)
                        .s3KeyPrefix("exec-command-output")
                        .build())
                .logging(ExecuteCommandLogging.OVERRIDE)
                .build())
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Vpc vpc;

var kmsKey = new Key(this, "KmsKey");

// Pass the KMS key in the `encryptionKey` field to associate the key to the log group
var logGroup = new LogGroup(this, "LogGroup", new LogGroupProps {
    EncryptionKey = kmsKey
});

// Pass the KMS key in the `encryptionKey` field to associate the key to the S3 bucket
var execBucket = new Bucket(this, "EcsExecBucket", new BucketProps {
    EncryptionKey = kmsKey
});

var cluster = new Cluster(this, "Cluster", new ClusterProps {
    Vpc = vpc,
    ExecuteCommandConfiguration = new ExecuteCommandConfiguration {
        KmsKey = kmsKey,
        LogConfiguration = new ExecuteCommandLogConfiguration {
            CloudWatchLogGroup = logGroup,
            CloudWatchEncryptionEnabled = true,
            S3Bucket = execBucket,
            S3EncryptionEnabled = true,
            S3KeyPrefix = "exec-command-output"
        },
        Logging = ExecuteCommandLogging.OVERRIDE
    }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc

kmsKey := kms.NewKey(this, jsii.String("KmsKey"))

// Pass the KMS key in the `encryptionKey` field to associate the key to the log group
logGroup := logs.NewLogGroup(this, jsii.String("LogGroup"), &LogGroupProps{
	EncryptionKey: kmsKey,
})

// Pass the KMS key in the `encryptionKey` field to associate the key to the S3 bucket
execBucket := s3.NewBucket(this, jsii.String("EcsExecBucket"), &BucketProps{
	EncryptionKey: kmsKey,
})

cluster := ecs.NewCluster(this, jsii.String("Cluster"), &ClusterProps{
	Vpc: Vpc,
	ExecuteCommandConfiguration: &ExecuteCommandConfiguration{
		KmsKey: *KmsKey,
		LogConfiguration: &ExecuteCommandLogConfiguration{
			CloudWatchLogGroup: logGroup,
			CloudWatchEncryptionEnabled: jsii.Boolean(true),
			S3Bucket: execBucket,
			S3EncryptionEnabled: jsii.Boolean(true),
			S3KeyPrefix: jsii.String("exec-command-output"),
		},
		Logging: ecs.ExecuteCommandLogging_OVERRIDE,
	},
})
```

## Members

| Member | Description |
| --- | --- |
| `NONE` | The execute command session is not logged. |
| `DEFAULT` | The awslogs configuration in the task definition is used. |
| `OVERRIDE` | Specify the logging details as a part of logConfiguration. |

## Referenced by

- [`ExecuteCommandConfiguration`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ExecuteCommandConfiguration.html).logging
