Last active
July 3, 2019 06:06
-
-
Save masayoshi634/905efd0c49f5d90ad599179f6ec280e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -ex | |
PROFILE=${AWS_PROFILE:="default"} | |
REGION=${AWS_REGION:="ap-northeast-1"} | |
print_help() { | |
cat <<-EOF >> /dev/stdout | |
Select and get log for cloudwatch logs | |
Depends: | |
awslogs (https://github.com/jorgebastida/awslogs) | |
peco (https://github.com/peco/peco) | |
Usage: $0 [-p AWS_PROFILE] [-r AWS_REGION] [-- awslogs_get_options] | |
Options: | |
-p [AWS_PROFILE] AWS Profile | |
-r [AWS_REGION] AWS Region | |
-h print this message and exit | |
Example: $0 -p test-account -r ap-northeast-1 -- -S --timestamp --start=10m -w | |
EOF | |
} | |
while getopts "p:r:h" opt; do | |
case ${opt} in | |
p ) PROFILE=${OPTARG} ;; | |
r ) REGION=${OPTARG} ;; | |
h ) print_help; exit ;; | |
* ) print_help; exit 1 ;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
AWSLOGS_ARGS=${*} | |
echo "awslogs groups --profile="${PROFILE}" --aws-region="${REGION}" | peco | xargs -I%% awslogs get --profile="${PROFILE}" --aws-region="${REGION}" ${AWSLOGS_ARGS} %%" | |
LOG_GROUP=$(awslogs groups --profile="${PROFILE}" --aws-region="${REGION}" | peco) | |
echo "awslogs get --profile="${PROFILE}" --aws-region="${REGION}" ${AWSLOGS_ARGS} ${LOG_GROUP}" | |
awslogs get --profile="${PROFILE}" --aws-region="${REGION}" ${AWSLOGS_ARGS} ${LOG_GROUP} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment