mirror of
https://github.com/20kaushik02/CSE546_Cloud_Computing_Projects.git
synced 2025-12-06 06:34:06 +00:00
modified as userdata script, finishing up part-1
This commit is contained in:
parent
2d833a1379
commit
73b1151d1c
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
||||
node_modules/
|
||||
*.log
|
||||
*.ps1
|
||||
*.zip
|
||||
|
||||
5
Project-1/Part-1/README.md
Normal file
5
Project-1/Part-1/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Part-1: Starting out - EC2 instance, EIP, web tier (lookup)
|
||||
|
||||
- `instance_info.py` describes the instances on the *us-east-1* region
|
||||
- `run_instances.py` launches one new instance, and associates the EIP 34.232.196.35 with it
|
||||
- The `instance_run` script is passed as user-data to the launched instance, to be executed upon first boot
|
||||
@ -1,6 +1,9 @@
|
||||
#!/bin/bash
|
||||
# https://stackoverflow.com/a/71648116/7630441
|
||||
sudo -u ubuntu -i <<'EOF'
|
||||
|
||||
# initializing instance
|
||||
cd /home/ubuntu
|
||||
cd ~
|
||||
sudo apt update
|
||||
sudo apt upgrade -y
|
||||
|
||||
@ -21,3 +24,5 @@ npm i
|
||||
# Start
|
||||
pm2 start npm --name webTier -- run prod
|
||||
pm2 save
|
||||
|
||||
EOF
|
||||
|
||||
@ -4,17 +4,21 @@ import boto3
|
||||
session = boto3.Session(profile_name="dev")
|
||||
dev_ec2_client = session.client("ec2", region_name="us-east-1")
|
||||
|
||||
with open("instance_run", "r") as setup_f:
|
||||
user_data = setup_f.read()
|
||||
|
||||
# Create capacity reservation of instances
|
||||
ami_id = "ami-0c7217cdde317cfec" # Ubuntu Server 22.04 LTS, SSD on EBS, 64-bit (x86)
|
||||
reservation = dev_ec2_client.run_instances(
|
||||
ImageId=ami_id,
|
||||
InstanceType="t2.micro",
|
||||
KeyName='cse546-dev',
|
||||
MinCount=1, # if available instances are less than min_count, abort with no allocation
|
||||
MaxCount=1, # try to allocate max_count instances. we only need one for now
|
||||
InstanceType="t2.micro",
|
||||
TagSpecifications=[
|
||||
{"ResourceType": "instance", "Tags": [{"Key": "Name", "Value": "web-instance"}]}
|
||||
],
|
||||
UserData=user_data
|
||||
)
|
||||
|
||||
print("Instances allocated successfully:", "Yes" if reservation else "No")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user