This project automates AWS resource provisioning and management using Bash scripts and AWS CLI. It sets up a VPC, subnet, security group, and an EC2 instance hosting a simple NGINX server with a static webpage. The project also deploys two Lambda functions and schedules them using EventBridge rules to automatically start and stop the EC2 instance daily.
.
├── LICENSE
├── README.md
├── ec2-keypair.pem
├── resources.json
├── scripts
│ ├── common.sh
│ ├── destroy.sh
│ ├── ec2_setup.sh
│ ├── events.sh
│ ├── lambda.sh
│ ├── main.sh
│ ├── networking.sh
├── start_ec2.py
├── stop_ec2.py
├── templates
│ ├── ec2_access_policy.json
│ ├── role_assume_policy.json
│ └── user_data.sh
- scripts/: Contains all automation scripts.
- templates/: Stores JSON templates for IAM policies and EC2 instance initialization.
- resources.json: Tracks created AWS resource IDs for easier cleanup.
- Install the AWS CLI.
- Configure your AWS CLI by running:
Provide your AWS Access Key, Secret Access Key, Default Region, and Output Format.
aws configure
- Ensure you have the necessary IAM permissions to manage EC2, IAM, Lambda, and EventBridge resources.
- Install
jqfor JSON parsing in the scripts. - Grant execute permissions to all scripts by running:
chmod +x scripts/*.sh
Clone the project repository to your local machine:
git clone https://github.com/ravikiranvm/aws-cli-project
cd aws-cli-projectRun the scripts sequentially to set up the infrastructure. Always execute the scripts from the project's root directory.
To deploy the entire stack in one step, run:
./scripts/main.shThis script sequentially executes all necessary setup scripts.
-
Networking Setup:
./scripts/networking.sh
Sets up the VPC, Subnet, Internet Gateway, Route Table, and Security Group.
-
EC2 Setup:
./scripts/ec2_setup.sh
Creates an EC2 key pair and launches an instance in the configured network.
-
Lambda Functions Deployment:
./scripts/lambda.sh
Deploys Lambda functions for starting and stopping the EC2 instance.
-
EventBridge Rules Configuration:
./scripts/events.sh
Sets up EventBridge rules to trigger the Lambda functions on a schedule.
To delete all created AWS resources, run:
./scripts/destroy.shThis script reads resources.json to identify and remove the resources.
- Ensure the
ec2-keypair.pemfile is securely stored. It is used to SSH into the EC2 instance. - Modify scripts as needed to customize resource configurations.
- If any script fails, debug using the output messages or logs.
- Github Actions for CI/CD
This project is licensed under the MIT License. See the LICENSE file for details.
