
ターミナルからクラウドウォッチログをテールする最良の方法。
著者-Luca Grulla -https://www.lucagrulla.com
Local TimeZoneまたはUTC (デフォルト)のいずれかで作業します。2d1h20mが2日、1時間20分前を示す。13:10の今日の13:10を示します。2018-10-20T8:53 。cw tail my-auth-service my-web 。--grep )およびGREPV ( --grepv )。--queryフラグと一致)echo my-group | cw tailアンドcat groups.txt | cw tail 。cw tail -f my-stream >> myfile.txt 。--no-colorフラグはありません。--profileおよび--regionフラグを使用して実現できます。 brew tap lucagrulla/tap
brew install cwbrew tap lucagrulla/tap
brew install cw [リリース]ページから.debまたは.rpmをダウンロードし、それぞれdpkg -iとrpm -iでインストールします。
注:3.3.0にアップグレードする場合は、新しいエイリアスコマンドに注意してください。これは、Snapcraftの新しいリリースルールに準拠するために必要です。
snap install cw-sh
sudo snap connect cw-sh:dot-aws-config-credentials
sudo snap alias cw-sh.cw cw cw厳格な閉じ込めで実行されます。 dot-aws-config-credentialsインターフェイス接続は.aws/configおよび.aws/credentialsファイルにアクセスするために必要です
scoop bucket add cw https://github.com/lucagrulla/cw-scoop-bucket.git
scoop install cwgo get github.com/lucagrulla/cw--profile=profile-name接続に使用されるAWSプロファイルをオーバーライドします。--region=aws-regionターゲットAWS領域をオーバーライドします。--no-color色付きの出力を無効にします。--endpointターゲットAWSエンドポイントURL。デフォルトでは、CWはデフォルトのAWSエンドポイントを使用します。--no-version-checkモジュールの新しいバージョンが利用可能であるかどうかをチェックします。cw lsリストグループ内のすべてのロググループ/ログストリーム
Usage: cw ls <command>
show an entity
Flags:
-h, --help Show context-sensitive help.
--endpoint=URL The target AWS endpoint url. By default cw will use the default aws endpoints. NOTE: v4.0.0
dropped the flag short version.
--profile=PROFILE The target AWS profile. By default cw will use the default profile defined in the
.aws/credentials file. NOTE: v4.0.0 dropped the flag short version.
--region=REGION The target AWS region. By default cw will use the default region defined in the
.aws/credentials file. NOTE: v4.0.0 dropped the flag short version.
--no-color Disable coloured output.NOTE: v4.0.0 dropped the flag short version.
--version Print version information and quit
--no-version-check Ignore checks if a newer version of the module is available.
Commands:
ls groups
Show all groups.
ls streams <group>
Show all streams in a given log group.
cw: error: expected one of "groups", "streams" cw tail特定のロググループ/ログストリーム
Usage: cw tail <groupName[:logStreamPrefix]> ...
Tail log groups/streams.
Arguments:
<groupName[:logStreamPrefix]> ... The log group and stream name, with group:prefix syntax. Stream name can be just the prefix. If no stream name is specified all stream names in the given
group will be tailed. Multiple group/stream tuple can be passed. e.g. cw tail group1:prefix1 group2:prefix2 group3:prefix3.
Flags:
-h, --help Show context-sensitive help.
--endpoint=URL The target AWS endpoint url. By default cw will use the default aws endpoints. NOTE: v4.0.0 dropped the flag short version.
--profile=PROFILE The target AWS profile. By default cw will use the default profile defined in the .aws/credentials file. NOTE: v4.0.0 dropped the flag short version.
--region=REGION The target AWS region. By default cw will use the default region defined in the .aws/credentials file. NOTE: v4.0.0 dropped the flag short version.
--no-color Disable coloured output.NOTE: v4.0.0 dropped the flag short version.
--version Print version information and quit
--no-version-check Ignore checks if a newer version of the module is available.
-f, --follow Don't stop when the end of streams is reached, but rather wait for additional data to be appended.
-t, --timestamp Print the event timestamp.
-i, --event-id Print the event Id.
-s, --stream-name Print the log stream name this event belongs to.
-n, --group-name Print the log group name this event belongs to.
-r, --retry Keep trying to open a log group/log stream if it is inaccessible.
-b, --start="2021-04-11T08:21:52" The UTC start time. Passed as either date/time or human-friendly format. The human-friendly format accepts the number of days, hours and minutes prior to
the present. Denote days with 'd', hours with 'h' and minutes with 'm' i.e. 80m, 4h30m, 2d4h. If just time is used (format: hh[:mm]) it is expanded to
today at the given time. Full available date/time format: 2017-02-27[T09[:00[:00]].
-e, --end=STRING The UTC end time. Passed as either date/time or human-friendly format. The human-friendly format accepts the number of days, hours and minutes prior to the
present. Denote days with 'd', hours with 'h' and minutes with 'm' i.e. 80m, 4h30m, 2d4h. If just time is used (format: hh[:mm]) it is expanded to today at
the given time. Full available date/time format: 2017-02-27[T09[:00[:00]].
-l, --local Treat date and time in Local timezone.
-g, --grep=STRING Pattern to filter logs by. See http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html for syntax.
-v, --grepv=STRING Equivalent of grep --invert-match. Invert match pattern to filter logs by.
-q, --query=STRING Equivalent of the --query flag in AWS CLI. Takes a JMESPath expression to filter JSON logs by. If the query fails (e.g. the log message was not JSON) then the original line is returned. 利用可能なロググループのリスト
cw ls groups特定のロググループのログストリームのリスト
cw ls streams my-log-group尾と指定されたロググループ/ストリームに従います
cw tail -f my-log-groupcw tail -f my-log-group:my-log-stream-prefixcw tail -f my-log-group:my-log-stream-prefix my-log-group2cw tail -f my-log-group:my-log-stream-prefix -b2017-01-01T08:10:10 -e2017-01-01T08:05:00cw tail -f my-log-group:my-log-stream-prefix -b7d 7日前から開始します。cw tail -f my-log-group:my-log-stream-prefix -b3h 3時間前から始まります。cw tail -f my-log-group:my-log-stream-prefix -b100m 100分前から開始します。cw tail -f my-log-group:my-log-stream-prefix -b2h30m 2時間30分前から開始します。cw tail -f my-log-group -b9:00 -e9:01JMESPATH構文を使用してJSONログをクエリします
cw tail -f my-log-group --query "machines[?state=='running'].name"時間と日付は、デフォルトでUTCとして扱われます。ローカルゾーンを使用する場合は、 --localフラグを使用してください。
cw 、ターゲットAWS領域を識別するために、認証と共有構成(.aws/config)にデフォルトの資格情報プロファイル(./aws/credentialsに保存)を使用します。プロファイルと領域の両方が、 profileとregionグローバルフラグを介して過度に配置されます。
AWS SSOはあなたの場合にサポートされています:
defaultまたは代替指定プロファイル)を使用しますsso_start_url 、 sso_account_id 、 sso_role_nameなどaws sso login経由を含むエラーメッセージが表示された場合...failed to sign request: failed to retrieve credentials: the SSO session has expired or is invalid... aws sso loginを介してSSOセッションを更新する必要があります(必要に応じて、指定されたプロファイルを指定します)。
cwを使用しますAWSで要求されるようにHTTP_PROXY環境変数を使用してください:https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-proxy.html
ここを読んでください