Skip to content

Commit 8a81e31

Browse files
committed
[update] - add more helpful commandlines for s3
1 parent 5bb8c9b commit 8a81e31

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

services/s3.sh

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@ aws_s3_list() {
88
aws_run_commandline 'aws s3api list-buckets --query "Buckets[].Name"'
99
}
1010

11+
aws_s3_get_bucket() {
12+
aws_s3_bucket_name=$1
13+
aws_run_commandline \
14+
"
15+
aws s3 ls s3://${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}
16+
"
17+
18+
}
19+
20+
aws_s3_get_bucket_recursived() {
21+
aws_s3_bucket_name=$1
22+
aws_run_commandline \
23+
"
24+
aws s3 ls s3://${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'} --recursive
25+
"
26+
}
27+
28+
aws_s3_get_bucket_with_hint() {
29+
aws_s3_get_bucket $(echo "$(peco_aws_s3_list)" | peco)
30+
}
31+
32+
aws_s3_get_bucket_recursived_with_hint() {
33+
aws_s3_get_bucket_recursived $(echo "$(peco_aws_s3_list)" | peco)
34+
}
35+
1136
aws_s3_get_object_metadata() {
1237
bucket_name=$1
1338
object_key=$2
@@ -19,12 +44,12 @@ aws_s3_get_object_metadata() {
1944

2045
}
2146

22-
aws_s3_get_s3_bucket_arn() {
47+
aws_s3_get_bucket_arn() {
2348
aws_s3_bucket_name=$1
2449
echo "arn:aws:s3:::${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}"
2550
}
2651

27-
aws_s3_get_s3_bucket_arn_with_hint() {
52+
aws_s3_get_bucket_arn_with_hint() {
2853
aws_s3_get_s3_bucket_arn $(echo "$(peco_aws_s3_list)" | peco)
2954
}
3055

@@ -45,3 +70,21 @@ aws_s3_create() {
4570
--bucket ${aws_s3_bucket_name:?"aws_s3_bucket_name is unset or empty"} \
4671
--create-bucket-configuration LocationConstraint=${AWS_REGION}
4772
}
73+
74+
aws_s3_delete() {
75+
aws_s3_bucket_name=$1
76+
echo "We didn't run the commandline, we just suggest the commandline"
77+
echo "If you want ot process it please run the commandline \
78+
[
79+
aws_s3_get_bucket_recursived ${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}
80+
aws s3 rm s3://${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}/ --recursive
81+
aws_s3_get_bucket_recursived ${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}
82+
aws s3api delete-bucket --bucket ${aws_s3_bucket_name:?'aws_s3_bucket_name is unset or empty'}
83+
aws_s3_ls
84+
]
85+
"
86+
}
87+
88+
aws_s3_rm_with_hint() {
89+
aws_s3_delete $(echo "$(peco_aws_s3_list)" | peco)
90+
}

0 commit comments

Comments
 (0)