Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Using the PutLogEvents API to send manually-created embedded metric format logs

Focus mode
Using the PutLogEvents API to send manually-created embedded metric format logs - Amazon CloudWatch

You can send embedded metric format logs to CloudWatch Logs using the CloudWatch Logs PutLogEvents API. When calling PutLogEvents, you have the option to include the following HTTP header, which tells CloudWatch Logs the metrics should be extracted, but it's not required.

x-amzn-logs-format: json/emf

The following is a full example using the AWS SDK for Java 2.x:

package org.example.basicapp; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsClient; import software.amazon.awssdk.services.cloudwatchlogs.model.DescribeLogStreamsRequest; import software.amazon.awssdk.services.cloudwatchlogs.model.DescribeLogStreamsResponse; import software.amazon.awssdk.services.cloudwatchlogs.model.InputLogEvent; import software.amazon.awssdk.services.cloudwatchlogs.model.PutLogEventsRequest; import java.util.Collections; public class EmbeddedMetricsExample { public static void main(String[] args) { final String usage = "To run this example, supply a Region code (eg. us-east-1), log group, and stream name as command line arguments" + "Ex: PutLogEvents <region-id> <log-group-name> <stream-name>"; if (args.length != 3) { System.out.println(usage); System.exit(1); } String regionId = args[0]; String logGroupName = args[1]; String logStreamName = args[2]; CloudWatchLogsClient logsClient = CloudWatchLogsClient.builder().region(Region.of(regionId)).build(); // Build a JSON log using the EmbeddedMetricFormat. long timestamp = System.currentTimeMillis(); String message = "{" + " \"_aws\": {" + " \"Timestamp\": " + timestamp + "," + " \"CloudWatchMetrics\": [" + " {" + " \"Namespace\": \"MyApp\"," + " \"Dimensions\": [[\"Operation\"], [\"Operation\", \"Cell\"]]," + " \"Metrics\": [{ \"Name\": \"ProcessingLatency\", \"Unit\": \"Milliseconds\", \"StorageResolution\": 60 }]" + " }" + " ]" + " }," + " \"Operation\": \"Aggregator\"," + " \"Cell\": \"001\"," + " \"ProcessingLatency\": 100" + "}"; InputLogEvent inputLogEvent = InputLogEvent.builder() .message(message) .timestamp(timestamp) .build(); // Specify the request parameters. PutLogEventsRequest putLogEventsRequest = PutLogEventsRequest.builder() .logEvents(Collections.singletonList(inputLogEvent)) .logGroupName(logGroupName) .logStreamName(logStreamName) .build(); logsClient.putLogEvents(putLogEventsRequest); System.out.println("Successfully put CloudWatch log event"); } }
Note

With the embedded metric format, you can track the processing of your EMF logs by metrics that are published in the AWS/Logs namespace of your account. These can be used to track failed metric generation from EMF, as well as whether failures happen due to parsing or validation. For more details see Monitoring with CloudWatch metrics.

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.