1- # brew install peco
2- # PECO
3-
41peco_assume_role_name () {
52 cat ~ /.aws/config | grep -e " ^\[profile.*\]$" | peco
63}
74
85peco_format_name_convention_pre_defined () {
9- peco_input=$1
6+ local peco_input=$1
107 echo " ${peco_input} " | tr " \t" " \n" | tr -s " " " \n" | tr -s ' \n'
118}
129
1310peco_format_aws_output_text () {
14- peco_input=$1
11+ local peco_input=$1
1512 echo " ${peco_input} " | tr " \t" " \n"
1613}
1714
@@ -20,37 +17,63 @@ peco_aws_acm_list() {
2017}
2118
2219peco_name_convention_input () {
23- text_input=$1
24- format_text=$( peco_format_name_convention_pre_defined $text_input )
20+ local text_input=$1
21+ local format_text=$( peco_format_name_convention_pre_defined $text_input )
22+ echo $format_text
23+ }
24+
25+ peco_create_menu_with_array_input () {
26+ local text_input=$1
27+ local format_text=$( peco_format_name_convention_pre_defined $text_input )
2528 echo $format_text
2629}
2730
31+ peco_aws_disable_input_cached () {
32+ export peco_input_expired_time=0
33+ }
34+
2835peco_aws_input () {
29- aws_cli_commandline=" ${1} --output text"
30- result_cached=$2
36+ peco_commandline_input " ${1} --output text" $2
37+ }
38+
39+ peco_commandline_input () {
3140
32- md5_hash=$( echo $aws_cli_commandline | md5)
33- input_folder=${aws_cli_input_tmp} /${ASSUME_ROLE}
41+ local commandline=" ${1} "
42+ local result_cached=$2
43+
44+ local md5_hash=$( echo $commandline | md5)
45+ local input_folder=${aws_cli_input_tmp} /${ASSUME_ROLE}
3446 mkdir -p ${input_folder}
35- input_file_path=" ${input_folder} /${md5_hash} .txt"
36- empty_file=$( find ${input_folder} -name ${md5_hash} .txt -empty)
47+ local input_file_path=" ${input_folder} /${md5_hash} .txt"
48+ local empty_file=$( find ${input_folder} -name ${md5_hash} .txt -empty)
49+ local valid_file=$( find ${input_folder} -name ${md5_hash} .txt -mmin +${peco_input_expired_time} )
3750
3851 # The file is existed and not empty and the flag result_cached is not empty
39- if [ -f " ${input_file_path} " ] && [ -z " ${empty_file} " ] && [ -n " ${result_cached} " ]; then
52+ if [ -z " ${valid_file} " ] && [ - f " ${input_file_path} " ] && [ -z " ${empty_file} " ] && [ -n " ${result_cached} " ]; then
4053 # Ignore the first line.
4154 grep -Ev " \*\*\*\*\*\*\*\* \[.*\]" $input_file_path
4255 else
43- aws_result=$( eval $aws_cli_commandline )
44- format_text=$( peco_format_aws_output_text $aws_result )
56+ local aws_result=$( aws_run_commandline_with_retry " $commandline " " false" )
57+
58+ local format_text=$( peco_format_aws_output_text $aws_result )
4559
4660 if [ -n " ${format_text} " ]; then
47- echo " ******** [ ${aws_cli_commandline } ] ********" > ${input_file_path}
61+ echo " ******** [ ${commandline } ] ********" > ${input_file_path}
4862 echo ${format_text} | tee -a ${input_file_path}
4963 else
5064 echo " Can not get the data"
5165 fi
5266
5367 fi
68+
69+ }
70+
71+ peco_create_menu () {
72+ local input_function=$1
73+ local peco_options=$2
74+ local peco_command=" peco ${peco_options} "
75+ local input_value=$( echo " $( eval $input_function ) " | eval ${peco_command} )
76+ echo ${input_value:? ' Can not get the input from peco menu' }
5477}
5578
5679# AWS Logs
@@ -69,10 +92,25 @@ peco_aws_ecs_list_services() {
6992
7093# AWS ECR
7194
72- peco_aws_list_repositorie_names () {
95+ peco_aws_ecr_list_repositorie_names () {
7396 peco_aws_input ' aws ecr describe-repositories --query "*[].repositoryName"' ' true'
7497}
7598
99+ peco_aws_ecr_list_images () {
100+ aws_ecr_repo_name=$1
101+ peco_aws_input " aws ecr list-images \
102+ --repository-name ${aws_ecr_repo_name:? ' aws_ecr_repo_name is unset or empy' } \
103+ --query \" imageIds[].{imageTag:imageTag}\" "
104+ }
105+
106+ peco_aws_alb_list_listners () {
107+ aws_alb_arn=$1
108+ peco_aws_input " \
109+ aws elbv2 describe-listeners \
110+ --load-balancer-arn ${aws_alb_arn:? ' aws_alb_arn is unset or empty' } \
111+ --query \" Listeners[*].ListenerArn\" "
112+ }
113+
76114# AWS RDS
77115peco_aws_list_db_parameter_groups () {
78116 peco_aws_input ' aws rds describe-db-parameter-groups --query "*[].DBParameterGroupName"' ' true'
@@ -108,3 +146,36 @@ peco_aws_codebuild_list() {
108146peco_aws_codepipeline_list () {
109147 peco_aws_input ' aws codepipeline list-pipelines --query "*[].name"' ' true'
110148}
149+
150+ # Codedeploy
151+ peco_aws_codedeploy_list_deployment_ids () {
152+ peco_aws_input ' aws deploy list-deployments --query "deployments[]"'
153+ }
154+
155+ # Cloudfront
156+ peco_aws_cloudfront_list () {
157+ commandline=" aws cloudfront list-distributions \
158+ --query 'DistributionList.Items[*].{AId:Id,BComment:Comment}' --output text | tr -s '\t' '_'"
159+ peco_commandline_input ${commandline} ' true'
160+ }
161+
162+ # Autoscaling group
163+ peco_aws_autoscaling_list () {
164+ peco_aws_input ' aws autoscaling describe-auto-scaling-groups --query "*[].AutoScalingGroupName"' ' true'
165+ }
166+
167+ # IAM role list
168+ peco_aws_iam_list_roles () {
169+ peco_aws_input ' aws iam list-roles --query "*[].{RoleName:RoleName}"' ' true'
170+ }
171+
172+ peco_aws_iam_list_attached_policies () {
173+ peco_aws_input ' aws iam list-policies --scope Local --only-attached --query "*[].Arn"' ' true'
174+ }
175+
176+ # EC2 Instance
177+ peco_aws_ec2_list () {
178+
179+ commandline=" aws ec2 describe-instances --filters Name=instance-state-name,Values=running --query 'Reservations[].Instances[].{Name: Tags[?Key==\` Name\` ].Value | [0],InstanceId:InstanceId}' --output text | tr -s '\t' '_'"
180+ peco_commandline_input ${commandline} ' true'
181+ }
0 commit comments