Skip to content

Commit 6b68c22

Browse files
authored
Merge pull request #36 from lamhaison/develop
Add some functions and update the documents
2 parents 4c57c12 + 0639da8 commit 6b68c22

File tree

6 files changed

+64
-4
lines changed

6 files changed

+64
-4
lines changed

main.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,22 @@ LHS_BIND_KEY=${3:-'True'}
9595

9696
if [[ ${LHS_BIND_KEY} == "True" && "$(which zle)" != "" ]]; then
9797
# Add hot-keys
98-
# zle -N aws_help
98+
99+
# For aws helper function
100+
zle -N aws_help
101+
bindkey '^h' aws_help
102+
103+
# For assume role
99104
zle -N aws_main_function
100105
bindkey '^@' aws_main_function
101106

107+
# For building the aws cli commandline
102108
zle -N aws_get_command
103109
# Hotkey: Option + a + c
104110
bindkey 'åç' aws_get_command
105-
106111
bindkey '' aws_get_command
107112

113+
# For get history
108114
zle -N aws_history
109115
# Hotkey Option + ah
110116
bindkey '˙' aws_history

services/assume_role.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ aws_assume_role_get_credential() {
104104

105105
assume_role_result=""
106106

107-
aws_assume_role_expired_time_from_config=$(aws configure get profile.${ASSUME_ROLE}.assume_role_timeout)
107+
# aws_assume_role_expired_time_from_config=$(aws configure get profile.${ASSUME_ROLE}.assume_role_timeout)
108+
# improve performance
109+
aws_assume_role_expired_time_from_config=60
108110

109111
# Check input invalid
110112
if [[ -n "$aws_assume_role_expired_time_from_config" ]]; then

services/aws_cost.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,31 @@ function aws_cost_list_months_later() {
1919
--time-period "Start=$(date -d "${months} months ago" +%Y-%m-01),End=$(date -d "$(date +%Y-%m-01) -1 day" +%Y-%m-%d)" \
2020
--granularity MONTHLY --metrics "UnblendedCost"
2121
}
22+
23+
function aws_cost_get_current_month() {
24+
aws ce get-cost-and-usage \
25+
--time-period "Start=$(date +%Y-%m-01),End=$(date +%Y-%m-%d)" \
26+
--granularity MONTHLY --metrics "UnblendedCost"
27+
}
28+
29+
function aws_cost_get_last_month() {
30+
aws ce get-cost-and-usage \
31+
--time-period "Start=$(date -d "$(date +%Y-%m-01) -1 month" +%Y-%m-01),End=$(date -d "$(date +%Y-%m-01) -1 day" +%Y-%m-%d)" \
32+
--granularity MONTHLY --metrics "UnblendedCost"
33+
}
34+
35+
function aws_cost_get_service_cost_current_month() {
36+
aws ce get-cost-and-usage \
37+
--time-period Start=$(date +%Y-%m-01),End=$(date -d "+1 day" +%Y-%m-%d) \
38+
--granularity MONTHLY \
39+
--metrics "UnblendedCost" \
40+
--group-by Type=DIMENSION,Key=SERVICE \
41+
--output table
42+
}
43+
44+
function aws_cost_get_last_7_days() {
45+
aws ce get-cost-and-usage \
46+
--time-period "Start=$(date -d "7 days ago" +%Y-%m-%d),End=$(date +%Y-%m-%d)" \
47+
--granularity DAILY --metrics "UnblendedCost" \
48+
--output table
49+
}

services/ec2/ec2_autoscaling.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ aws_autoscaling_list() {
1818
LTID:MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId,\
1919
LTVersion:MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.Version,\
2020
LTName:MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateName,\
21-
DesiredCapacity:DesiredCapacity}" \
21+
MinSize:MinSize,\
22+
DesiredCapacity:DesiredCapacity,\
23+
MaxSize:MaxSize}" \
2224
--output table
2325
'
2426
}

services/ecr.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,24 @@ function aws_ecr_pull_image_with_hint() { # To get the docker image and pull it
9292
${aws_ecr_repo_image_tag:?'aws_ecr_repo_image_tag is uset or empty'}
9393

9494
}
95+
96+
97+
# ECR for helmchart
98+
function aws_ecr_login_for_helm() {
99+
if [[ -z "${AWS_ACCOUNT_ID}" ]]; then
100+
aws_assume_role_get_aws_account_id
101+
fi
102+
103+
local aws_ecr_helm_docker_login_password
104+
local aws_ecr_helm_docker_login_cmd
105+
106+
aws_ecr_helm_docker_login_password=$(aws ecr get-login-password --region ${AWS_REGION})
107+
108+
aws_ecr_helm_docker_login_cmd=$(
109+
echo "echo '${aws_ecr_helm_docker_login_password}' | helm registry login \
110+
--username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
111+
)
112+
113+
aws_run_commandline "${aws_ecr_helm_docker_login_cmd}"
114+
115+
}

services/s3.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,4 @@ function aws_s3_cp_folder_instruction() {
158158
"
159159

160160
}
161+

0 commit comments

Comments
 (0)