-
Notifications
You must be signed in to change notification settings - Fork 758
Pratik #10
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?
Pratik #10
Conversation
WalkthroughA new Bash script, Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Script
participant AWS CLI
participant AWS EC2
User->>Script: Run create_ec2.sh
Script->>Script: check_awscli()
alt AWS CLI not installed
Script->>Script: install_awscli()
alt Installation fails
Script-->>User: Exit with error
end
end
Script->>Script: main() sets parameters
Script->>Script: create_ec2_instance()
Script->>Script: Validate instance name
alt Name is "Shell-Script-EC2-Demo"
Script-->>User: Print error and exit
else
Script->>AWS CLI: aws ec2 run-instances
AWS CLI->>AWS EC2: Create instance
AWS EC2-->>AWS CLI: Return instance ID
Script->>Script: wait_for_instance(instance_id)
Script->>AWS CLI: aws ec2 describe-instances (polling)
AWS CLI->>AWS EC2: Check instance state
AWS EC2-->>AWS CLI: Instance running
Script-->>User: Print success message
end
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
♻️ Duplicate comments (4)
create_ec2.sh (4)
4-9
: Duplicate of thecheck_awscli
return-based change inday04/create_ec2.sh
; returning an error code instead of exiting directly is approved here as well.
79-81
: Duplicate of the main installation logic change fromday04/create_ec2.sh
; handling ofinstall_awscli
inmain
is correct.
66-69
: Duplicate of the instance name validation issue identified inday04/create_ec2.sh
; please move this check before therun-instances
command and usedescribe-instances
to detect existing instances.
87-92
: Duplicate of the hardcoded defaults feedback fromday04/create_ec2.sh
; consider parameterizing these values for better flexibility.
🧹 Nitpick comments (1)
day04/create_ec2.sh (1)
87-92
: Hardcoded AWS resource IDs reduce flexibility
Embedding fixed AMI, key pair, subnet, security group IDs, and instance name limits reusability across environments. Consider accepting these as CLI flags or environment variables so users can override them without editing the script.For example, use
getopts
:while getopts "a:t:k:s:g:n:" opt; do case $opt in a) AMI_ID="$OPTARG" ;; t) INSTANCE_TYPE="$OPTARG" ;; k) KEY_NAME="$OPTARG" ;; s) SUBNET_ID="$OPTARG" ;; g) SECURITY_GROUP_IDS="$OPTARG" ;; n) INSTANCE_NAME="$OPTARG" ;; *) echo "Usage: $0 -a ami -t type -k key -s subnet -g sg1,sg2 -n name" >&2; exit 1 ;; esac done
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
create_ec2.sh
(1 hunks)day04/create_ec2.sh
(2 hunks)
🔇 Additional comments (2)
day04/create_ec2.sh (2)
4-9
: Return code handling in check_awscli is well separated
Switching from an immediateexit
to returning an error code allowsmain
to manage installation logic and keeps side effects localized.
79-81
: Explicit AWS CLI installation in main
Good job moving the installation decision intomain
, which now cleanly handles failures fromcheck_awscli
and installs the AWS CLI only when needed.
Add validation to prevent duplicate EC2 instance names:
PS : learning github and git, any mistake please let me know :) |
Summary by CodeRabbit
New Features
Bug Fixes
Enhancements