1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CloudWatchのログをlocalにdownload

Posted at

CloudWatchのをlocalにdownloadしたい

get-log-eventsで落とせるとおもったけど、これloopさせないと全部取れないんですね。

download.sh
#!/bin/bash
log_group_name=$1
log_stream_name=$2
response=`aws logs get-log-events --log-group-name ${log_group_name} --log-stream-name "${log_stream_name}" --start-from-head`
next_token=`echo $response | jq -r '.nextForwardToken'`
while [ -n "${next_token}" ]; do
    echo ${response} | jq -r .events[].message
    response=`aws logs get-log-events --log-group-name ${log_group_name} --log-stream-name "${log_stream_name}" --start-from-head --next-token ${next_token}`
    next_token=`echo $response | jq -r '.nextForwardToken'`
    if [[ $(echo ${response} | jq -e '.events == []') == "true" ]]; then
        break
fi
done
./download.sh /aws/lambda/hoge '2020/00/00/[$LATEST]xxxxxx'

注意 lambdaのlog streamは$があるのでシングルクォートで囲む

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?