-
Notifications
You must be signed in to change notification settings - Fork 47
/
creator.sh
232 lines (212 loc) · 8.45 KB
/
creator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/bash
Green='\033[0;32m'
Red='\033[0;31m'
NC='\033[0m'
if [ -z "$1" ]
then
infra_env='dev'
else
infra_env=$1
fi
if [ $infra_env != "dev" -a $infra_env != "qa" -a $infra_env != "sandbox" ]
then
echo "Environment name can only be dev or qa or sandbox. example 'sh creator.sh dev' "
exit 1
fi
echo "Environment: $infra_env"
deployment_region=$(curl -s http://169.254.169.254/task/AvailabilityZone | sed 's/\(.*\)[a-z]/\1/')
embed_model_id='cohere.embed-english-v3'
if [ -z "$deployment_region" ]
then
printf "$Red !!! Cannot detect region. Manually select your AWS Cloudshell region from the below list $NC"
printf "\n"
printf "$Green Please enter your current AWS cloudshell region (1/2/3/4/5/6): $NC"
printf "\n"
region_options=("N-Virginia" "Oregon" "Tokyo" "Mumbai" "Frankfurt" "Sydney" "Quit")
select region_opts in "${region_options[@]}"
do
case $region_opts in
"N-Virginia")
deployment_region='us-east-1'
printf "$Green Deploy in US East(N.Virginia) $NC"
printf "$Green Embedding model $embed_model_id $NC"
printf "\n"
;;
"Oregon")
deployment_region='us-west-2'
printf "$Green Deploy in US West(Oregon) $NC"
printf "$Green Embedding model $embed_model_id $NC"
;;
# "ap-southeast-1")
# deployment_region='ap-southeast-1'
# printf "$Green Deploy in Asia Pacific (Singapore) $NC"
# ;;
"Tokyo")
deployment_region='ap-northeast-1'
printf "$Green Deploy in Asia Pacific (Tokyo) $NC"
embed_model_id='cohere.embed-english-v3'
printf "$Green Embedding model $embed_model_id $NC"
;;
"Mumbai")
deployment_region='ap-south-1'
printf "$Green Deploy in Asia Pacific (Mumbai) $NC"
embed_model_id='cohere.embed-english-v3'
printf "$Green Embedding model $embed_model_id $NC"
;;
"Frankfurt")
deployment_region='eu-central-1'
printf "$Green Deploy in Europe (Frankfurt) $NC"
printf "$Green Embedding model $embed_model_id $NC"
;;
"Sydney")
deployment_region='ap-southeast-2'
printf "$Green Deploy in Asia Pacific (Sydney) $NC"
embed_model_id='cohere.embed-english-v3'
printf "$Green Embedding model $embed_model_id $NC"
;;
"Quit")
printf "$Red Quit deployment $NC"
exit 1
break
;;
*)
printf "$Red Exiting, Invalid option $REPLY. Select from 1/2/3/4/5/6 $NC"
exit 1;;
esac
break
done
fi
echo "Selected region: $deployment_region "
echo '*************************************************************'
echo ' '
echo '*************************************************************'
echo ' '
printf "$Green Do you want to deploy Opensearch Serverless or Just try out Amazon Bedrock: $NC"
printf "\n"
options=("Yes - Deploy Amazon Opensearch Serverless vector engine for RAG" "No - I will only test Amazon Bedrock without RAG" "Quit")
aoss_selected='yes'
select opt in "${options[@]}"
do
case $opt in
"Yes - Deploy Amazon Opensearch Serverless vector engine for RAG")
aoss_selected='yes'
;;
"No - I will only test Amazon Bedrock without RAG")
aoss_selected='no'
printf "$Green You can re-run this script to deploy Opensearch Serverless later $NC"
;;
"Quit")
printf "$Red Quit deployment $NC"
exit 1
break
;;
*)
printf "$Red Exiting, Invalid option $REPLY . Select from 1/2/3 $NC"
exit 1
;;
esac
break
done
echo ' '
echo '*************************************************************'
echo ' '
printf "$Green Press Enter to proceed with deployment else ctrl+c to cancel $NC "
read -p " "
cd ..
echo "--- Upgrading npm ---"
sudo npm install n stable -g
echo "--- Installing cdk ---"
sudo npm install -g aws-cdk@2.91.0
echo "--- Bootstrapping CDK on account in region $deployment_region ---"
cdk bootstrap aws://$(aws sts get-caller-identity --query "Account" --output text)/$deployment_region
cd serverless-rag-demo
echo "--- pip install requirements ---"
python3 -m pip install -r requirements.txt
echo "--- CDK synthesize ---"
cdk synth -c environment_name=$infra_env -c current_timestamp=$CURRENT_UTC_TIMESTAMP -c is_aoss=$aoss_selected -c embed_model_id=$embed_model_id
echo "--- CDK deploy ---"
CURRENT_UTC_TIMESTAMP=$(date -u +"%Y%m%d%H%M%S")
echo Setting Tagging Lambda Image with timestamp $CURRENT_UTC_TIMESTAMP
cdk deploy -c environment_name=$infra_env -c current_timestamp=$CURRENT_UTC_TIMESTAMP -c is_aoss="$aoss_selected" -c embed_model_id=$embed_model_id LlmsWithServerlessRag"$infra_env"Stack --require-approval never
echo "--- Get Build Container ---"
project=lambdaragllmcontainer"$infra_env"
echo project: $project
build_container=$(aws codebuild list-projects|grep -o $project'[^,"]*')
echo container: $build_container
echo "--- Trigger Build ---"
BUILD_ID=$(aws codebuild start-build --project-name $build_container | jq '.build.id' -r)
echo Build ID : $BUILD_ID
if [ "$?" != "0" ]; then
echo "Could not start CodeBuild project. Exiting."
exit 1
else
echo "Build started successfully."
fi
echo "Check build status every 30 seconds. Wait for codebuild to finish"
j=0
while [ $j -lt 50 ];
do
sleep 30
echo 'Wait for 30 seconds. Build job typically takes 15 minutes to complete...'
build_status=$(aws codebuild batch-get-builds --ids $BUILD_ID | jq -cs '.[0]["builds"][0]["buildStatus"]')
build_status="${build_status%\"}"
build_status="${build_status#\"}"
if [ $build_status = "SUCCEEDED" ] || [ $build_status = "FAILED" ] || [ $build_status = "STOPPED" ]
then
echo "Build complete: $latest_build : status $build_status"
break
fi
((j++))
done
if [ $build_status = "SUCCEEDED" ]
then
COLLECTION_ENDPOINT=https://dummy-vector-endpoint.amazonaws.com
if [ $aoss_selected = "yes" ]
then
COLLECTION_NAME=$(jq '.context.'$infra_env'.collection_name' cdk.json -r)
COLLECTION_ENDPOINT=$(aws opensearchserverless batch-get-collection --names $COLLECTION_NAME |jq '.collectionDetails[0]["collectionEndpoint"]' -r)
fi
cdk deploy -c environment_name=$infra_env -c collection_endpoint=$COLLECTION_ENDPOINT -c current_timestamp=$CURRENT_UTC_TIMESTAMP -c is_aoss=$aoss_selected -c embed_model_id=$embed_model_id ApiGwLlmsLambda"$infra_env"Stack --require-approval never
echo "---Deploying the UI ---"
project=ragllmuicontainer"$infra_env"
echo project: $project
build_container=$(aws codebuild list-projects|grep -o $project'[^,"]*')
echo container: $build_container
echo "--- Trigger UI Build ---"
BUILD_ID=$(aws codebuild start-build --project-name $build_container | jq '.build.id' -r)
echo Build ID : $BUILD_ID
if [ "$?" != "0" ]; then
echo "Could not start UI CodeBuild project. Exiting."
exit 1
else
echo "UI Build started successfully."
fi
echo "Check UI build status every 30 seconds. Wait for codebuild to finish"
j=0
while [ $j -lt 50 ];
do
sleep 10
echo 'Wait for 30 seconds. Build job typically takes 5 minutes to complete...'
build_status=$(aws codebuild batch-get-builds --ids $BUILD_ID | jq -cs '.[0]["builds"][0]["buildStatus"]')
build_status="${build_status%\"}"
build_status="${build_status#\"}"
if [ $build_status = "SUCCEEDED" ] || [ $build_status = "FAILED" ] || [ $build_status = "STOPPED" ]
then
echo "Build complete: $latest_build : status $build_status"
break
fi
((j++))
done
if [ $build_status = "SUCCEEDED" ]
then
echo "Host UI on AppRunner..."
cdk deploy -c environment_name=$infra_env -c collection_endpoint=$COLLECTION_ENDPOINT -c current_timestamp=$CURRENT_UTC_TIMESTAMP -c is_aoss=$aoss_selected -c embed_model_id=$embed_model_id AppRunnerHosting"$infra_env"Stack --require-approval never
else
echo "Exiting. Build did not succeed."
exit 1
fi
else
echo "Exiting. Build did not succeed."
exit 1
fi
echo "Deployment Complete"