aws-cdk-lib.aws_ecs.AwsLogDriver

class AwsLogDriver

LanguageType name
.NETAmazon.CDK.AWS.ECS.AwsLogDriver
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsecs#AwsLogDriver
Javasoftware.amazon.awscdk.services.ecs.AwsLogDriver
Pythonaws_cdk.aws_ecs.AwsLogDriver
TypeScript (source)aws-cdk-lib » aws_ecs » AwsLogDriver

Extends LogDriver

A log driver that sends log information to CloudWatch Logs.

Example

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 min)'),
});

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

new AwsLogDriver(props: AwsLogDriverProps)

Parameters

  • props AwsLogDriverProps — the awslogs log driver configuration options.

Constructs a new instance of the AwsLogDriver class.

Properties

NameTypeDescription
logGroup?ILogGroupThe log group to send log streams to.

logGroup?

Type: ILogGroup (optional)

The log group to send log streams to.

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

Methods

NameDescription
bind(scope, containerDefinition)Called when the log driver is configured on a container.

bind(scope, containerDefinition)

public bind(scope: Construct, containerDefinition: ContainerDefinition): LogDriverConfig

Parameters

  • scope Construct
  • containerDefinition ContainerDefinition

Returns

  • LogDriverConfig

Called when the log driver is configured on a container.