# AwsLogDriver

A log driver that sends log information to CloudWatch Logs.

Extends: LogDriver › AwsLogDriver

- Source: [`aws-ecs/lib/log-drivers/aws-log-driver.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-ecs/lib/log-drivers/aws-log-driver.ts#L106)

## Example

```ts
declare const cluster: ecs.Cluster;
// Create a Task Definition for the container to start
const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef');
taskDefinition.addContainer('TheContainer', {
  image: ecs.ContainerImage.fromAsset(path.resolve(__dirname, '..', 'eventhandler-image')),
  memoryLimitMiB: 256,
  logging: new ecs.AwsLogDriver({ streamPrefix: 'EventDemo', mode: ecs.AwsLogDriverMode.NON_BLOCKING }),
});

// An Rule that describes the event trigger (in this case a scheduled run)
const rule = new events.Rule(this, 'Rule', {
  schedule: events.Schedule.expression('rate(1 minute)'),
});

// Pass an environment variable to the container 'TheContainer' in the task
rule.addTarget(new targets.EcsTask({
  cluster,
  taskDefinition,
  taskCount: 1,
  containerOverrides: [{
    containerName: 'TheContainer',
    environment: [{
      name: 'I_WAS_TRIGGERED',
      value: 'From CloudWatch Events'
    }],
  }],
}));
```

## Initializer

```ts
new AwsLogDriver(props: AwsLogDriverProps)
```

## Properties

- `logGroup`: [ILogGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_logs.ILogGroup.html) — The log group to send log streams to.

  Only available after the LogDriver has been bound to a ContainerDefinition.

## Methods

- `awsLogs(props: AwsLogDriverProps): LogDriver` (static) — Creates a log driver configuration that sends log information to CloudWatch Logs.

- `bind(scope: Construct, containerDefinition: ContainerDefinition): LogDriverConfig` — Called when the log driver is configured on a container.
