Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This is the project to collect helpful aws cli commandlines with complex options
- Sometimes, you want to add more options on purpose and you want to have a place to collect and reuse it in the future. That is the reason I defined that structure to help me collect helpful commandlines and share on the github.
- You have a lot of assume role profile, you can search it by peco and assume it one time by caching feature instead of filling in MFA every time. You can re-use assume-role in the other tab of Iterm.


# Setup manually
## Setup dependencies
Notes: This document is for macos environment.

Expand Down Expand Up @@ -46,7 +46,9 @@ echo "random_string" > ~/.password_assume_role_encrypted
```


## Settings when open terminal (I am using iterm)
## Setup the aws-cli-utils

### Setup from source code
```
sudo mkdir -p /opt/lamhaison-tools
chown $(whoami) /opt/lamhaison-tools
Expand All @@ -73,6 +75,27 @@ echo "source /opt/lamhaison-tools/aws-cli-utils/main.sh" >> ~/.zshrc

```

### Setup from homebrew
#### Install
```
brew tap lamhaison/aws-cli-utils
brew install --verbose --debug aws-cli-utils
```
## Load when start an Iterm terminal
Add these lines to ~/.bashrc or ~/.zshrc or ~/.bash_profile
```
source "$(which aws-cli-utils.sh)" "/opt/homebrew/Cellar/aws-cli-utils/$(brew info aws-cli-utils | head -1 | awk -F "stable " '{print $2}')" "${HOME}" "True"

```

### Re-install the latest version
```
brew uninstall --verbose --debug aws-cli-utils
brew untap lamhaison/aws-cli-utils
brew tap lamhaison/aws-cli-utils
brew install --verbose --debug aws-cli-utils
```

## Setting AWS credentials
### The file ~/.aws/config
```
Expand Down
39 changes: 39 additions & 0 deletions aws-cli-utils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Documentation: https://docs.brew.sh/Formula-Cookbook
# https://rubydoc.brew.sh/Formula
# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
class V180 < Formula
desc "aws-cli-utils"
homepage "https://github.com/lamhaison/aws-cli-utils"
url "https://github.com/lamhaison/aws-cli-utils/archive/refs/tags/v1.8.0.tar.gz"
sha256 "bef5b298d17dbfad86bdebeb08384dd848dae165beb2f9e0538c1f3508852963"
license "Apache-2.0"

# depends_on "cmake" => :build

depends_on "jq"
depends_on "peco"

def install
# ENV.deparallelize # if your formula fails when building in parallel
# Remove unrecognized options if warned by configure
# https://rubydoc.brew.sh/Formula.html#std_configure_args-instance_method
# system "./configure", *std_configure_args, "--disable-silent-rules"
# system "cmake", "-S", ".", "-B", "build", *std_cmake_args

prefix.install "README.md"
prefix.install "LICENSE"
end

test do
# `test do` will create, run in and delete a temporary directory.
#
# This test will fail and we won't accept that! For Homebrew/homebrew-core
# this will need to be a test that verifies the functionality of the
# software. Run the test with `brew test v1.8.0`. Options passed
# to `brew install` such as `--HEAD` also need to be provided to `brew test`.
#
# The installed folder is not in the path, so use the entire path to any
# executables being tested: `system "#{bin}/program", "do", "something"`.
system "false"
end
end
4 changes: 2 additions & 2 deletions common/logging.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash

aws_assume_role_check_log() {
aws_assume_role_get_log() {
local log_file_path=${aws_cli_logs}/${ASSUME_ROLE}.log
echo "Read the log ${log_file_path}"
view +$ -c 'set number' ${log_file_path}
}

aws_assume_role_check_log_uploaded() {
aws_assume_role_get_log_uploaded() {
local log_file_path=${aws_cli_logs}/${ASSUME_ROLE}-uploaded.log
echo "Read the log ${log_file_path}"
view +$ -c 'set number' ${log_file_path}
Expand Down
32 changes: 24 additions & 8 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# @script main.sh
# @description TODO : to load function for aws-cli-utils
# $1: Where is looking for sh files and source the list
# $2: Do you want to set the bind key?
# $2: Where do you want to save logs?
# $3: Do you want to set the bind key?

AWS_CLI_SOURCE_SCRIPTS=$1

Expand All @@ -19,14 +20,26 @@ else
export AWS_CLI_SOURCE_SCRIPTS=${AWS_CLI_SOURCE_SCRIPTS}
fi

AWS_CLI_DATA=$2
if [[ -z "${AWS_CLI_DATA}" ]]; then
LOCAL_AWS_CLI_DATA=$(dirname -- "$0")
if [[ "${LOCAL_AWS_CLI_DATA}" = "." ]]; then
DEFAULT_AWS_CLI_DATA='/opt/lamhaison-tools/aws-cli-utils'
fi

export AWS_CLI_DATA="${LOCAL_AWS_CLI_DATA:-${DEFAULT_AWS_CLI_DATA}}"
else
export AWS_CLI_DATA=${AWS_CLI_DATA}
fi

export assume_role_password_encrypted="$(cat ~/.password_assume_role_encrypted)"
export tmp_credentials="/tmp/aws_temporary_credentials"

export aws_cli_results="${AWS_CLI_SOURCE_SCRIPTS}/aws_cli_results"
export aws_cli_logs="${AWS_CLI_SOURCE_SCRIPTS}/aws_cli_results/logs"
export aws_cli_images="${AWS_CLI_SOURCE_SCRIPTS}/aws_cli_results/images"
export aws_cli_input_tmp="${AWS_CLI_SOURCE_SCRIPTS}/aws_cli_results/inputs"
export aws_cli_input_folder="${AWS_CLI_SOURCE_SCRIPTS}/aws_cli_inputs"
export aws_cli_results="${AWS_CLI_DATA}/aws_cli_results"
export aws_cli_logs="${AWS_CLI_DATA}/aws_cli_results/logs"
export aws_cli_images="${AWS_CLI_DATA}/aws_cli_results/images"
export aws_cli_input_tmp="${AWS_CLI_DATA}/aws_cli_results/inputs"
export aws_cli_input_folder="${AWS_CLI_DATA}/aws_cli_inputs"
export aws_cli_list_commands_folder="${aws_cli_input_folder}/aws_services_commands"
export aws_tmp_input="/tmp/aws_tmp_input_23647494949484.txt"
export aws_cli_document_root_url="https://awscli.amazonaws.com/v2/documentation/api/latest/reference"
Expand Down Expand Up @@ -58,7 +71,10 @@ alias get-account-alias='aws iam list-account-aliases'
alias get-account-id='echo AccountId $(aws sts get-caller-identity --query "Account" --output text)'

# Import sub-commandlines.
for script in $(find ${AWS_CLI_SOURCE_SCRIPTS} -type f -name '*.sh' | grep -v main.sh | grep -v main.sh | grep -v test.sh | grep -v temp.sh); do
for script in $(
find ${AWS_CLI_SOURCE_SCRIPTS} -type f -name '*.sh' |
grep -v main.sh | grep -v main.sh | grep -v test.sh | grep -v temp.sh | grep -v aws-cli-utils.sh
); do
source $script
done

Expand All @@ -71,7 +87,7 @@ if [ "true" = "${aws_cli_load_current_assume_role}" ] && [ -s "${aws_cli_current
aws_assume_role_load_current_assume_role_for_new_tab
fi

LHS_BIND_KEY=${2:-'True'}
LHS_BIND_KEY=${3:-'True'}

if [[ "${LHS_BIND_KEY}" = "True" ]]; then
# Add hot-keys
Expand Down
4 changes: 4 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
install:
echo "Todo later"


8 changes: 5 additions & 3 deletions services/logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ aws_logs_list() {

aws_logs_tail() {
aws_log_group_name=$1
local aws_logs_sinces=${2:-$aws_log_tail_since}
echo Get log of the group name ${aws_log_group_name:?"aws_log_group_name is unset or empty"}
echo "Running commandline [ aws logs tail --follow $aws_log_group_name --since ${aws_log_tail_since} ]"
aws logs tail --follow $aws_log_group_name --since ${aws_log_tail_since}
local aws_cmd="aws logs tail --follow $aws_log_group_name --since ${aws_logs_sinces}"
lhs_commandline_logging "${aws_cmd}"
eval ${aws_cmd}
}

aws_logs_tail_with_hint() {
echo "Your log group name >"
aws_log_group_name=$(peco_create_menu 'peco_aws_logs_list')

aws_logs_tail $aws_log_group_name
aws_logs_tail $aws_log_group_name $1
}