vinayakrevankar commited on
Commit
951d434
·
1 Parent(s): 8a00a9b

added AWS deployment script

Browse files
Files changed (1) hide show
  1. deploy_aws.sh +78 -0
deploy_aws.sh ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Variables
4
+ CLUSTER_NAME="CS553"
5
+ TASK_DEFINITION_NAME="CSS553_CaseStudy_4"
6
+ CONTAINER_NAME="CaseStudy4Image"
7
+ IMAGE_URI="venkateshroshan/mlops-cs4:latest"
8
+ VCPU="0.5"
9
+ MEMORY="2048"
10
+ PORT="7860"
11
+ SECURITY_GROUP_NAME="CS553-SG"
12
+
13
+ echo "Starting ECS setup..."
14
+
15
+ # Step 1: Create ECS Cluster
16
+ echo "Creating ECS cluster: $CLUSTER_NAME..."
17
+ aws ecs create-cluster --cluster-name $CLUSTER_NAME
18
+ echo "ECS cluster $CLUSTER_NAME created successfully."
19
+
20
+ # Step 2: Register Task Definition
21
+ echo "Registering task definition: $TASK_DEFINITION_NAME..."
22
+ aws ecs register-task-definition \
23
+ --family $TASK_DEFINITION_NAME \
24
+ --network-mode awsvpc \
25
+ --requires-compatibilities FARGATE \
26
+ --cpu $VCPU \
27
+ --memory $MEMORY \
28
+ --container-definitions "[
29
+ {
30
+ \"name\": \"$CONTAINER_NAME\",
31
+ \"image\": \"$IMAGE_URI\",
32
+ \"portMappings\": [
33
+ {
34
+ \"containerPort\": $PORT,
35
+ \"protocol\": \"tcp\"
36
+ }
37
+ ],
38
+ \"essential\": true
39
+ }
40
+ ]"
41
+ echo "Task definition $TASK_DEFINITION_NAME registered successfully."
42
+
43
+ # Step 3: Get Default VPC ID
44
+ echo "Retrieving default VPC ID..."
45
+ VPC_ID=$(aws ec2 describe-vpcs --filters "Name=isDefault,Values=true" --query "Vpcs[0].VpcId" --output text)
46
+ if [ -z "$VPC_ID" ]; then
47
+ echo "Error: Default VPC not found. Exiting."
48
+ exit 1
49
+ fi
50
+ echo "Default VPC ID: $VPC_ID."
51
+
52
+ # Step 4: Create Security Group
53
+ echo "Creating security group: $SECURITY_GROUP_NAME..."
54
+ SECURITY_GROUP_ID=$(aws ec2 create-security-group --group-name $SECURITY_GROUP_NAME --description "Security group for CS553 task" --vpc-id $VPC_ID --query 'GroupId' --output text)
55
+ echo "Security group created with ID: $SECURITY_GROUP_ID."
56
+
57
+ # Step 5: Add Inbound Rule to Security Group
58
+ echo "Adding inbound rule to security group for port $PORT..."
59
+ aws ec2 authorize-security-group-ingress \
60
+ --group-id $SECURITY_GROUP_ID \
61
+ --protocol tcp \
62
+ --port $PORT \
63
+ --cidr 0.0.0.0/0
64
+ echo "Inbound rule added successfully."
65
+
66
+ # Step 6: Run ECS Task
67
+ echo "Running ECS task in cluster $CLUSTER_NAME..."
68
+ aws ecs run-task \
69
+ --cluster $CLUSTER_NAME \
70
+ --launch-type FARGATE \
71
+ --network-configuration "awsvpcConfiguration={
72
+ subnets=[\"$(aws ec2 describe-subnets --filters Name=vpc-id,Values=$VPC_ID --query 'Subnets[0].SubnetId' --output text)\"],
73
+ securityGroups=[\"$SECURITY_GROUP_ID\"],
74
+ assignPublicIp=\"ENABLED\"}" \
75
+ --task-definition $TASK_DEFINITION_NAME
76
+ echo "Task is running in cluster $CLUSTER_NAME."
77
+
78
+ echo "ECS setup completed successfully."