AWS CloudWatch
Since Camel 3.1
Only producer is supported
The AWS2 Cloudwatch component allows messages to be sent to an Amazon CloudWatch metrics. The implementation of the Amazon API is provided by the AWS SDK.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon CloudWatch. More information is available at Amazon CloudWatch.
URI Format
aws2-cw://namespace[?options]
The metrics will be created if they don’t already exist.
You can append query options to the URI in the following format: ?options=value&option2=value&…
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The AWS CloudWatch component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
The configuration that the endpoints of this component start from. Each endpoint gets a copy of it, and the options of the endpoint replace its values. | Cw2Configuration | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
The metric name. putMetricData uses it for the metric that it builds when the body is not a MetricDatum, listMetrics lists only the metrics with this name, and describeAlarmsForMetric, which requires a metric name, describes the alarms of this metric. The CamelAwsCwMetricName header replaces it. | String | ||
The operation that the producer performs: putMetricData puts metric data, listMetrics lists metrics, describeAlarms describes alarms, and describeAlarmsForMetric describes the alarms of one metric. The CamelAwsCwOperation header replaces this option. Enum values:
| putMetricData | Cw2Operations | |
Whether the CloudWatch client sends the requests to the URI of the uriEndpointOverride option instead of the CloudWatch endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
The ID of the AWS region of CloudWatch, in lower case, for example eu-west-1 (the value of Region.EU_WEST_1.id()). If not set, the AWS SDK resolves the region itself, for example from the AWS_REGION environment variable. Enum values:
| String | ||
The timestamp of the metric that putMetricData builds when the body is not a MetricDatum, as an ISO-8601 instant such as 2026-11-18T22:00:00Z. The CamelAwsCwMetricTimestamp header replaces it. If neither is set, CloudWatch uses the time it receives the data. CloudWatch accepts timestamps from up to two weeks in the past to up to two hours in the future. | Instant | ||
The unit of the metric that putMetricData builds when the body is not a MetricDatum: the name of a StandardUnit of CloudWatch, such as Count, Bytes, Percent or Kilobytes/Second, or its constant name, such as KILOBYTES_SECOND, in any case. An unknown unit fails the exchange. The CamelAwsCwMetricUnit header replaces it, and the unit is Count when neither is set. | String | ||
The URI that the CloudWatch client sends the requests to, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true. | String | ||
The value of the metric that putMetricData builds when the body is not a MetricDatum. The CamelAwsCwMetricValue header replaces it, and the value is 1 when neither is set. CloudWatch rejects NaN, infinity, and values outside the range -2360 to 2360. | Double | ||
Autowired To use a custom software.amazon.awssdk.services.cloudwatch.CloudWatchClient, which is autowired when the registry has a single one. When this option is set, the credentials, region, proxy, endpoint override and trustAllCertificates options are not used. The endpoint does not close a client that is set or autowired. | CloudWatchClient | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean | |
The host name of the proxy that the CloudWatch client uses. The client uses a proxy only when the proxyPort option is set too. | String | ||
The port of the proxy that the CloudWatch client uses. The client uses a proxy only when the proxyHost option is set too. | Integer | ||
The protocol of the proxy that the CloudWatch client uses. It is used only when the proxyHost and proxyPort options are both set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless amazonCwClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. The endpoint requires it, unless amazonCwClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. All three are then required: if one of the three is missing, creating the client fails. | String | ||
Whether the CloudWatch client accepts any TLS certificate of the server without checking it. It applies whether or not the endpoint is overridden. Use it only for tests, for example with a local emulator. | false | boolean | |
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Endpoint Options
The AWS CloudWatch endpoint is configured using URI syntax:
aws2-cw:namespace
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The CloudWatch namespace of the metrics, for example MyApp/Orders. putMetricData puts the metric data into it, listMetrics lists only the metrics of it, and describeAlarmsForMetric looks up the metric in it. The CamelAwsCwMetricNamespace header replaces it. putMetricData fails for a namespace that starts with AWS/, which CloudWatch reserves for the metrics of AWS services. | String |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The metric name. putMetricData uses it for the metric that it builds when the body is not a MetricDatum, listMetrics lists only the metrics with this name, and describeAlarmsForMetric, which requires a metric name, describes the alarms of this metric. The CamelAwsCwMetricName header replaces it. | String | ||
The operation that the producer performs: putMetricData puts metric data, listMetrics lists metrics, describeAlarms describes alarms, and describeAlarmsForMetric describes the alarms of one metric. The CamelAwsCwOperation header replaces this option. Enum values:
| putMetricData | Cw2Operations | |
Whether the CloudWatch client sends the requests to the URI of the uriEndpointOverride option instead of the CloudWatch endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
The ID of the AWS region of CloudWatch, in lower case, for example eu-west-1 (the value of Region.EU_WEST_1.id()). If not set, the AWS SDK resolves the region itself, for example from the AWS_REGION environment variable. Enum values:
| String | ||
The timestamp of the metric that putMetricData builds when the body is not a MetricDatum, as an ISO-8601 instant such as 2026-11-18T22:00:00Z. The CamelAwsCwMetricTimestamp header replaces it. If neither is set, CloudWatch uses the time it receives the data. CloudWatch accepts timestamps from up to two weeks in the past to up to two hours in the future. | Instant | ||
The unit of the metric that putMetricData builds when the body is not a MetricDatum: the name of a StandardUnit of CloudWatch, such as Count, Bytes, Percent or Kilobytes/Second, or its constant name, such as KILOBYTES_SECOND, in any case. An unknown unit fails the exchange. The CamelAwsCwMetricUnit header replaces it, and the unit is Count when neither is set. | String | ||
The URI that the CloudWatch client sends the requests to, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true. | String | ||
The value of the metric that putMetricData builds when the body is not a MetricDatum. The CamelAwsCwMetricValue header replaces it, and the value is 1 when neither is set. CloudWatch rejects NaN, infinity, and values outside the range -2360 to 2360. | Double | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Autowired To use a custom software.amazon.awssdk.services.cloudwatch.CloudWatchClient, which is autowired when the registry has a single one. When this option is set, the credentials, region, proxy, endpoint override and trustAllCertificates options are not used. The endpoint does not close a client that is set or autowired. | CloudWatchClient | ||
The host name of the proxy that the CloudWatch client uses. The client uses a proxy only when the proxyPort option is set too. | String | ||
The port of the proxy that the CloudWatch client uses. The client uses a proxy only when the proxyHost option is set too. | Integer | ||
The protocol of the proxy that the CloudWatch client uses. It is used only when the proxyHost and proxyPort options are both set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless amazonCwClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. The endpoint requires it, unless amazonCwClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. All three are then required: if one of the three is missing, creating the client fails. | String | ||
Whether the CloudWatch client accepts any TLS certificate of the server without checking it. It applies whether or not the endpoint is overridden. Use it only for tests, for example with a local emulator. | false | boolean | |
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Message Headers
The AWS CloudWatch component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelAwsCwOperation (producer) Constant: | The operation that the producer performs, which replaces the operation option: putMetricData, listMetrics, describeAlarms or describeAlarmsForMetric. | String | |
CamelAwsCwMetricNamespace (producer) Constant: | The CloudWatch namespace of the metric, which replaces the namespace of the endpoint for putMetricData, listMetrics and describeAlarmsForMetric. | String | |
CamelAwsCwMetricName (producer) Constant: | The metric name, which replaces the name option: the name of the metric that putMetricData builds when the body is not a MetricDatum, the name that listMetrics lists the metrics of, and the metric that describeAlarmsForMetric describes the alarms of. | String | |
CamelAwsCwMetricValue (producer) Constant: | The value of the metric that putMetricData builds when the body is not a MetricDatum, which replaces the value option. The value is 1 when neither is set. | Double | |
CamelAwsCwMetricUnit (producer) Constant: | The unit of the metric that putMetricData builds when the body is not a MetricDatum, which replaces the unit option: the name of a StandardUnit, such as Count, Bytes or Kilobytes/Second, or its constant name, in any case. The unit is Count when neither is set. | String | |
CamelAwsCwMetricTimestamp (producer) Constant: | The timestamp of the metric that putMetricData builds when the body is not a MetricDatum, an Instant or a java.util.Date, which replaces the timestamp option. If neither is set, CloudWatch uses the time it receives the data. | Instant | |
CamelAwsCwMetricDimensions (producer) Constant: | The dimensions, as a map of dimension names to dimension values. putMetricData adds them to the metric that it builds when the body is not a MetricDatum, unless the CamelAwsCwMetricDimensionName and CamelAwsCwMetricDimensionValue headers are both set. listMetrics lists only the metrics with these dimensions, where a null value matches any value of the dimension, and describeAlarmsForMetric describes the alarms of the metric with these dimensions. | Map | |
CamelAwsCwMetricDimensionName (producer) Constant: | The name of a single dimension that putMetricData adds to the metric that it builds when the body is not a MetricDatum. It is used only together with the CamelAwsCwMetricDimensionValue header, and the CamelAwsCwMetricDimensions header is then not used. The other operations do not use it. | String | |
CamelAwsCwMetricDimensionValue (producer) Constant: | The value of the single dimension of the CamelAwsCwMetricDimensionName header, which putMetricData adds to the metric that it builds when the body is not a MetricDatum. The other operations do not use it. | String | |
CamelAwsCwAlarmName (producer) Constant: | The name of the alarm that describeAlarms describes. If not set, describeAlarms describes all the metric alarms, or those in the state of the CamelAwsCwAlarmState header. | String | |
CamelAwsCwAlarmState (producer) Constant: | The state of the alarms that describeAlarms describes: OK, ALARM or INSUFFICIENT_DATA. | String | |
CamelAwsCwNextToken (producer) Constant: | The token of the next page of results of listMetrics and describeAlarms. On the request, the token that the previous call returned, to get the next page. After the call, the producer sets it to the token of the response, which is null on the last page. | String | |
CamelAwsCwMaxResults (producer) Constant: | The maximum number of alarms that describeAlarms returns in one page, from 1 to 100. listMetrics does not use it. | Integer | |
CamelAwsCwIsTruncated (producer) Constant: | Set by listMetrics and describeAlarms: true when the response has a next token, so more results can be fetched with the CamelAwsCwNextToken header. | Boolean |
Message Body
The message body at each side of the AWS CloudWatch component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Producer input |
| putMetricData sends a body that is a MetricDatum of the AWS SDK or a collection or an array of them, and an empty one or one with another element fails; with another body the metric comes from the CamelAwsCwMetric* headers or the name, value and unit options. The other operations do not use the body. |
Producer output |
| Unchanged after putMetricData, the default. The response of the AWS SDK for listMetrics, describeAlarms and describeAlarmsForMetric.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Required CW component options
You have to provide the amazonCwClient in the Registry, your accessKey and secretKey, or set useDefaultCredentialsProvider, useProfileCredentialsProvider or useSessionCredentials to true, to access the Amazon’s CloudWatch.
Usage
Static credentials, Default Credential Provider and Profile Credentials Provider
You have the possibility of avoiding the usage of explicit static credentials by specifying the useDefaultCredentialsProvider option and set it to true.
The order of evaluation for Default Credentials Provider is the following:
-
Java system properties -
aws.accessKeyIdandaws.secretKey. -
Environment variables -
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY. -
Web Identity Token from AWS STS.
-
The shared credentials and config files.
-
Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable
AWS_CONTAINER_CREDENTIALS_RELATIVE_URIis set. -
Amazon EC2 Instance profile credentials.
You have also the possibility of using Profile Credentials Provider, by specifying the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name.
Only one of static, default and profile credentials could be used at the same time.
For more information about this you can look at AWS credentials documentation
Advanced CloudWatchClient configuration
If you need more control over the CloudWatchClient instance configuration you can create your own instance and refer to it from the URI:
-
Java
-
XML
-
YAML
from("direct:start")
.to("aws2-cw://namespace?amazonCwClient=#client"); <route>
<from uri="direct:start"/>
<to uri="aws2-cw://namespace?amazonCwClient=#client"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: aws2-cw://namespace
parameters:
amazonCwClient: "#client" The #client refers to a CloudWatchClient in the Registry.
Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-aws2-cw</artifactId>
<version>${camel-version}</version>
</dependency> where ${camel-version} must be replaced by the actual version of Camel.
Examples
Producer Example
-
Java
-
XML
-
YAML
from("direct:start")
.to("aws2-cw://http://camel.apache.org/aws-cw"); <route>
<from uri="direct:start"/>
<to uri="aws2-cw://http://camel.apache.org/aws-cw"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: aws2-cw://http://camel.apache.org/aws-cw and sends something like
exchange.getIn().setHeader(Cw2Constants.METRIC_NAME, "ExchangesCompleted");
exchange.getIn().setHeader(Cw2Constants.METRIC_VALUE, "2.0");
exchange.getIn().setHeader(Cw2Constants.METRIC_UNIT, "Count"); The metric data of putMetricData
The putMetricData operation sends the body when it is a MetricDatum, or a collection or an array of MetricDatum (each element must be a MetricDatum, otherwise the exchange fails; an empty collection or array fails the exchange too, as there is no metric to put). For any other body, the metric is built from the headers and the options: CamelAwsCwMetricName or the name option, CamelAwsCwMetricValue or the value option (1 by default), CamelAwsCwMetricUnit or the unit option (Count by default), and CamelAwsCwMetricTimestamp or the timestamp option.
The unit is the name of a StandardUnit of the AWS SDK, such as Count, Bytes or Kilobytes/Second, in any case; an unknown unit fails the exchange. The timestamp header is an Instant or a java.util.Date.