class CloudWatchAgentIntegration (construct)
| Language | Type name |
|---|---|
.NET | Amazon.CDK.AWS.ApplicationSignals.Alpha.CloudWatchAgentIntegration |
Go | github.com/aws/aws-cdk-go/awscdkapplicationsignalsalpha/v2#CloudWatchAgentIntegration |
Java | software.amazon.awscdk.services.applicationsignals.alpha.CloudWatchAgentIntegration |
Python | aws_cdk.aws_applicationsignals_alpha.CloudWatchAgentIntegration |
TypeScript (source) | @aws-cdk/aws-applicationsignals-alpha ยป CloudWatchAgentIntegration |
Implements
IConstruct, IDependable
A construct that adds CloudWatch Agent as a container to an ECS task definition.
Example
import { Construct } from 'constructs';
import * as appsignals from '@aws-cdk/aws-applicationsignals-alpha';
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as ecs from 'aws-cdk-lib/aws-ecs';
class MyStack extends cdk.Stack {
public constructor(scope?: Construct, id?: string, props: cdk.StackProps = {}) {
super(scope, id, props);
const vpc = new ec2.Vpc(this, 'TestVpc', {});
const cluster = new ecs.Cluster(this, 'TestCluster', { vpc });
// Define Task Definition for CloudWatch agent (Daemon)
const cwAgentTaskDefinition = new ecs.Ec2TaskDefinition(this, 'CloudWatchAgentTaskDefinition', {
networkMode: ecs.NetworkMode.HOST,
});
new appsignals.CloudWatchAgentIntegration(this, 'CloudWatchAgentIntegration', {
taskDefinition: cwAgentTaskDefinition,
containerName: 'ecs-cwagent',
enableLogging: false,
cpu: 128,
memoryLimitMiB: 64,
portMappings: [
{
containerPort: 4316,
hostPort: 4316,
},
{
containerPort: 2000,
hostPort: 2000,
},
],
});
// Create the CloudWatch Agent daemon service
new ecs.Ec2Service(this, 'CloudWatchAgentDaemon', {
cluster,
taskDefinition: cwAgentTaskDefinition,
daemon: true, // Runs one container per EC2 instance
});
// Define Task Definition for user application
const sampleAppTaskDefinition = new ecs.Ec2TaskDefinition(this, 'SampleAppTaskDefinition', {
networkMode: ecs.NetworkMode.HOST,
});
sampleAppTaskDefinition.addContainer('app', {
image: ecs.ContainerImage.fromRegistry('test/sample-app'),
cpu: 0,
memoryLimitMiB: 512,
});
// No CloudWatch Agent side car is needed as application container communicates to CloudWatch Agent daemon through host network
new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', {
taskDefinition: sampleAppTaskDefinition,
instrumentation: {
sdkVersion: appsignals.PythonInstrumentationVersion.V0_8_0
},
serviceName: 'sample-app'
});
new ecs.Ec2Service(this, 'MySampleApp', {
cluster,
taskDefinition: sampleAppTaskDefinition,
desiredCount: 1,
});
}
}
Initializer
new CloudWatchAgentIntegration(scope: Construct, id: string, props: CloudWatchAgentIntegrationProps)
Parameters
- scope
Constructโ - The construct scope. - id
stringโ - The construct ID. - props
Cloudโ - Configuration properties.Watch Agent Integration Props
Creates a new CloudWatch Agent integration.
Construct Props
| Name | Type | Description |
|---|---|---|
| container | string | Name of the CloudWatch Agent container. |
| task | Task | The task definition to integrate CloudWatch agent into. |
| agent | string | Custom agent configuration in JSON format. |
| cpu? | number | The minimum number of CPU units to reserve for the container. |
| enable | boolean | Whether to enable logging for the CloudWatch Agent. |
| essential? | boolean | Start as an essential container. |
| memory | number | The amount (in MiB) of memory to present to the container. |
| memory | number | The soft limit (in MiB) of memory to reserve for the container. |
| operating | Operating | Operating system family for the CloudWatch Agent. |
| port | Port[] | The port mappings to add to the container definition. |
containerName
Type:
string
Name of the CloudWatch Agent container.
taskDefinition
Type:
Task
The task definition to integrate CloudWatch agent into.
[disable-awslint:ref-via-interface]
agentConfig?
Type:
string
(optional, default: Uses default configuration for Application Signals)
Custom agent configuration in JSON format.
cpu?
Type:
number
(optional, default: No minimum CPU units reserved.)
The minimum number of CPU units to reserve for the container.
enableLogging?
Type:
boolean
(optional, default: false)
Whether to enable logging for the CloudWatch Agent.
essential?
Type:
boolean
(optional, default: true)
Start as an essential container.
memoryLimitMiB?
Type:
number
(optional, default: No memory limit.)
The amount (in MiB) of memory to present to the container.
memoryReservationMiB?
Type:
number
(optional, default: No memory reserved.)
The soft limit (in MiB) of memory to reserve for the container.
operatingSystemFamily?
Type:
Operating
(optional, default: Linux)
Operating system family for the CloudWatch Agent.
portMappings?
Type:
Port[]
(optional, default: No ports are mapped.)
The port mappings to add to the container definition.
Properties
| Name | Type | Description |
|---|---|---|
| agent | Container | The CloudWatch Agent container definition. |
| node | Node | The tree node. |
agentContainer
Type:
Container
The CloudWatch Agent container definition.
node
Type:
Node
The tree node.
Methods
| Name | Description |
|---|---|
| to | Returns a string representation of this construct. |
| with(...mixins) | Applies one or more mixins to this construct. |
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
with(...mixins)
public with(...mixins: IMixin[]): IConstruct
Parameters
- mixins
IMixinโ The mixins to apply.
Returns
Applies one or more mixins to this construct.
Mixins are applied in order. The list of constructs is captured at the
start of the call, so constructs added by a mixin will not be visited.
Use multiple with() calls if subsequent mixins should apply to added
constructs.

.NET
Go
Java
Python
TypeScript (