-
Notifications
You must be signed in to change notification settings - Fork 795
CREATING S3 BUCKET USING SHELL SCRIPT #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| << TASK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| NAME: YATIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TASK: CREATE S3 BUCKET USING SHELL SCRIPT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TASK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| check_awscli(){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ! command -v aws &> /dev/null; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "AWS CLI not installed, Installing it" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| install_awscli | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "AWS CLI INSTALLED!" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| install_awscli(){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Download and install AWS CLI v2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| curl -s "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo apt-get install -y unzip &> /dev/null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unzip -q awscliv2.zip | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo ./aws/install | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Verify installation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aws --version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Clean up | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rm -rf awscliv2.zip ./aws | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Support cross-distro installation of unzip Proposed diff: install_awscli(){
@@
- sudo apt-get install -y unzip &> /dev/null
+ if command -v apt-get &> /dev/null; then
+ sudo apt-get install -y unzip &> /dev/null
+ elif command -v yum &> /dev/null; then
+ sudo yum install -y unzip &> /dev/null
+ else
+ echo "Error: Unsupported package manager. Please install 'unzip' manually."
+ exit 1
+ fi
@@
# Verify installation
aws --version
@@
# Clean up
rm -rf awscliv2.zip ./aws📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_s3_bucket(){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BUCKET_NAME=$1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REGION=$2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aws s3 mb s3://$BUCKET_NAME --region $REGION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo -e "------------------\nS3 Bucket $BUCKET_NAME created Successfully!!\n-------------------------" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| main(){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BUCKET_NAME="yatins-bucket" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REGION="us-east-1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| check_awscli | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if aws s3api head-bucket --bucket "$BUCKET_NAME" &> /dev/null; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo -e "-----------------------------\nBucket $BUCKET_NAME already exists. Skipping creation.\n----------------------------" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Creating Bucket in region $REGION" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_s3_bucket $BUCKET_NAME $REGION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| main | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misuse of here-document for metadata comments
A heredoc (
<< TASK … TASK) without a command will break the script (SC2188). It’s better to convert this block into shell comments or prepend a no-op.Suggested diff:
📝 Committable suggestion
🧰 Tools
🪛 Shellcheck (0.10.0)
[warning] 5-5: This redirection doesn't have a command. Move to its command (or use 'true' as no-op).
(SC2188)