|
| 1 | +# brew install peco |
| 2 | +# PECO |
| 3 | + |
| 4 | +peco_assume_role_name() { |
| 5 | + cat ~/.aws/config | grep -e "^\[profile.*\]$" | peco |
| 6 | +} |
| 7 | + |
| 8 | +peco_format_aws_output_text() { |
| 9 | + peco_input=$1 |
| 10 | + echo "${peco_input}" | tr "\t" "\n" |
| 11 | +} |
| 12 | + |
| 13 | +peco_aws_acm_list() { |
| 14 | + aws_acm_list | peco |
| 15 | +} |
| 16 | + |
| 17 | +peco_aws_input() { |
| 18 | + aws_cli_commandline="${1} --output text" |
| 19 | + result_cached=$2 |
| 20 | + |
| 21 | + md5_hash=$(echo $aws_cli_commandline | md5) |
| 22 | + input_folder=${aws_cli_input_tmp}/${ASSUME_ROLE} |
| 23 | + mkdir -p ${input_folder} |
| 24 | + input_file_path="${input_folder}/${md5_hash}.txt" |
| 25 | + empty_file=$(find ${input_folder} -name ${md5_hash}.txt -empty) |
| 26 | + |
| 27 | + # The file is existed and not empty and the flag result_cached is not empty |
| 28 | + if [ -f "${input_file_path}" ] && [ -z "${empty_file}" ] && [ -n "${result_cached}" ]; then |
| 29 | + # Ignore the first line. |
| 30 | + grep -Ev "\*\*\*\*\*\*\*\* \[.*\]" $input_file_path |
| 31 | + else |
| 32 | + aws_result=$(eval $aws_cli_commandline) |
| 33 | + format_text=$(peco_format_aws_output_text $aws_result) |
| 34 | + |
| 35 | + if [ -n "${format_text}" ]; then |
| 36 | + echo "******** [ ${aws_cli_commandline} ] ********" >${input_file_path} |
| 37 | + echo ${format_text} | tee -a ${input_file_path} |
| 38 | + else |
| 39 | + echo "Can not get the data" |
| 40 | + fi |
| 41 | + |
| 42 | + fi |
| 43 | +} |
| 44 | + |
| 45 | +# AWS Logs |
| 46 | +peco_aws_logs_list() { |
| 47 | + peco_aws_input 'aws logs describe-log-groups --query "*[].logGroupName"' 'true' |
| 48 | +} |
| 49 | + |
| 50 | +# AWS ECS |
| 51 | +peco_aws_ecs_list_clusters() { |
| 52 | + peco_aws_input 'aws ecs list-clusters --query "*[]"' 'true' |
| 53 | +} |
| 54 | + |
| 55 | +peco_aws_ecs_list_services() { |
| 56 | + peco_aws_input 'aws ecs list-services --cluster $aws_ecs_cluster_arn --query "*[]"' |
| 57 | +} |
| 58 | + |
| 59 | +# AWS ECR |
| 60 | + |
| 61 | +peco_aws_list_repositorie_names() { |
| 62 | + peco_aws_input 'aws ecr describe-repositories --query "*[].repositoryName"' 'true' |
| 63 | +} |
| 64 | + |
| 65 | +# AWS RDS |
| 66 | +peco_aws_list_db_parameter_groups() { |
| 67 | + peco_aws_input 'aws rds describe-db-parameter-groups --query "*[].DBParameterGroupName"' 'true' |
| 68 | +} |
| 69 | + |
| 70 | +peco_aws_list_db_cluster_parameter_groups() { |
| 71 | + peco_aws_input 'aws rds describe-db-cluster-parameter-groups --query "*[].DBClusterParameterGroupName"' 'true' |
| 72 | +} |
| 73 | + |
| 74 | +peco_aws_list_db_clusters() { |
| 75 | + peco_aws_input 'aws rds describe-db-clusters --query "*[].DBClusterIdentifier"' 'true' |
| 76 | +} |
| 77 | + |
| 78 | +peco_aws_list_db_instances() { |
| 79 | + peco_aws_input 'aws rds describe-db-instances --query "*[].DBInstanceIdentifier"' 'true' |
| 80 | +} |
| 81 | + |
| 82 | +# Lambda |
| 83 | +peco_aws_lambda_list() { |
| 84 | + peco_aws_input 'aws lambda list-functions --query "*[].FunctionName"' 'true' |
| 85 | +} |
| 86 | + |
| 87 | +# S3 |
| 88 | +peco_aws_s3_list() { |
| 89 | + peco_aws_input 'aws s3api list-buckets --query "Buckets[].Name"' 'true' |
| 90 | +} |
| 91 | + |
| 92 | +# Codebuild |
| 93 | +peco_aws_codebuild_list() { |
| 94 | + peco_aws_input 'aws codebuild list-projects --query "*[]"' 'true' |
| 95 | +} |
0 commit comments