
尾部AWS CloudWatch登录的最佳方法是从您的终端登录。
作者 - 卢卡·格拉拉(Luca Grulla)-https://www.lucagrulla.com
Local时区或UTC (默认)。2d1h20m表示2天,1小时20分钟前。13:10表示今天的13:10。2018-10-20T8:53 。cw tail my-auth-service my-web 。--grep )和GREPV ( --grepv )。--query Flag匹配)echo my-group | cw tail and cat groups.txt | cw tail 。cw tail -f my-stream >> myfile.txt 。--no-color标志。--profile 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严格限制运行;需要访问.aws/config和.aws/credentials文件,需要dot-aws-config-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:01使用jmespath语法查询JSON日志
cw tail -f my-log-group --query "machines[?state=='running'].name"默认情况下,时间和日期被视为UTC。如果您喜欢使用本地区域,请使用--local标志。
cw使用默认凭据配置文件(存储在./aws/credentials中)进行身份验证和共享配置(.aws/config)来识别目标AWS区域。轮廓和区域都可以通过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 CLI的要求使用HTTP_PROXY环境变量:https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-proxy.html
在这里阅读