AWS Log Insight Query

0

Hi,

I have a log insight query in that there is field named as instance_id it contains just 2 or more ec2 instance id's. I have a requirement of separating each ec2 instance in to a new field . Is there a way to get the each instance id in to a new field without using stats & hard coding the ec2 instance id. Because id's are dynamic and stats i need to perform some aggregation this instance id's

1 個回答
0

You can use the parse command along with regular expressions. This allows you to dynamically extract instance IDs from the log events.

Here's an example of how you can achieve this:

fields @timestamp, @message
| parse @message /instance_id:(?<InstanceId>[^\s]+)/
| display InstanceId, @timestamp, @message

In this example: The parse command is used with a regular expression to extract the EC2 instance ID from the @message field. The regular expression /instance_id:(?<InstanceId>[^\s]+)/ captures the value following "instance_id:" until the next whitespace character. The result is stored in the field named InstanceId. Adjust the regular expression based on your log format. This example assumes that the instance ID is followed by a colon and is followed by non-whitespace characters.

The display command is used to show the InstanceId, @timestamp, and @message fields, but you can adjust this based on your requirements.

This way, the query dynamically extracts instance IDs without hard-coding them, allowing you to adapt to different instance IDs in your logs.

AWS
已回答 6 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南