-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathcreate_config.sh
191 lines (163 loc) · 6 KB
/
create_config.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
#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# : "${STACK_ID_VPC:=sagemaker-hyperpod}"
# Check for JQ
if ! command -v jq &> /dev/null
then
echo -e "please install jq...\nsudo yum install -y jq or brew install jq"
exit 1
fi
# Define AWS Region
if [ -z ${AWS_REGION} ]; then
echo "[WARNING] AWS_REGION environment variable is not set, automatically set depending on aws cli default region."
export AWS_REGION=$(aws configure get region)
fi
echo "export AWS_REGION=${AWS_REGION}" >> env_vars
echo "[INFO] AWS_REGION = ${AWS_REGION}"
# Define Instances seperated by ','.
if [ -z ${INSTANCES} ]; then
echo "[WARNING] INSTANCES environment variable is not set, automatically set to g5.12xlarge."
export INSTANCES=g5.12xlarge
fi
echo "export INSTANCES=${INSTANCES}" >> env_vars
echo "[INFO] INSTANCES = ${INSTANCES}"
# Retrieve VPC ID
export VPC_ID=`aws cloudformation describe-stacks \
--stack-name $STACK_ID_VPC \
--query 'Stacks[0].Outputs[?OutputKey==\`VPC\`].OutputValue' \
--region ${AWS_REGION} \
--output text`
if [[ ! -z $VPC_ID ]]; then
echo "export VPC_ID=${VPC_ID}" >> env_vars
echo "[INFO] VPC_ID = ${VPC_ID}"
else
echo "[ERROR] failed to retrieve VPC ID"
return 1
fi
# Grab the subnet id
export SUBNET_ID=`aws cloudformation describe-stacks \
--stack-name $STACK_ID_VPC \
--query 'Stacks[0].Outputs[?OutputKey==\`PrimaryPrivateSubnet\`].OutputValue' \
--region ${AWS_REGION} \
--output text`
if [[ ! -z $SUBNET_ID ]]; then
echo "export SUBNET_ID=${SUBNET_ID}" >> env_vars
echo "[INFO] SUBNET_ID = ${SUBNET_ID}"
else
echo "[ERROR] failed to retrieve SUBNET ID"
return 1
fi
# Grab the backup subnet id
export BACKUP_SUBNET=`aws cloudformation describe-stacks \
--stack-name $STACK_ID_VPC \
--query 'Stacks[0].Outputs[?OutputKey==\`BackupPrivateSubnet\`].OutputValue' \
--region ${AWS_REGION} \
--output text`
if [[ ! -z $BACKUP_SUBNET ]]; then
echo "export BACKUP_SUBNET=${BACKUP_SUBNET}" >> env_vars
echo "[INFO] BACKUP_SUBNET = ${BACKUP_SUBNET}"
else
echo "[ERROR] failed to retrieve BACKUP SUBNET ID"
return 1
fi
# Grab the subnet id
export PUBLIC_SUBNET_ID=`aws cloudformation describe-stacks \
--stack-name $STACK_ID_VPC \
--query 'Stacks[0].Outputs[?OutputKey==\`PublicSubnet\`].OutputValue' \
--region ${AWS_REGION} \
--output text`
if [[ ! -z $PUBLIC_SUBNET_ID ]]; then
echo "export PUBLIC_SUBNET_ID=${PUBLIC_SUBNET_ID}" >> env_vars
echo "[INFO] PUBLIC_SUBNET_ID = ${PUBLIC_SUBNET_ID}"
else
echo "[ERROR] failed to retrieve Public SUBNET ID"
return 1
fi
# Get FSx Filesystem id from CloudFormation
export FSX_ID=`aws cloudformation describe-stacks \
--stack-name $STACK_ID_VPC \
--query 'Stacks[0].Outputs[?OutputKey==\`FSxLustreFilesystemId\`].OutputValue' \
--region ${AWS_REGION} \
--output text`
if [[ ! -z $FSX_ID ]]; then
echo "export FSX_ID=${FSX_ID}" >> env_vars
echo "[INFO] FSX_ID = ${FSX_ID}"
else
echo "[ERROR] failed to retrieve FSX ID"
return 1
fi
# Get FSx Filesystem Mountname from CloudFormation
export FSX_MOUNTNAME=`aws cloudformation describe-stacks \
--stack-name $STACK_ID_VPC \
--query 'Stacks[0].Outputs[?OutputKey==\`FSxLustreFilesystemMountname\`].OutputValue' \
--region ${AWS_REGION} \
--output text`
if [[ ! -z $FSX_MOUNTNAME ]]; then
echo "export FSX_MOUNTNAME=${FSX_MOUNTNAME}" >> env_vars
echo "[INFO] FSX_MOUNTNAME = ${FSX_MOUNTNAME}"
else
echo "[ERROR] failed to retrieve FSX Mountname"
return 1
fi
# Get FSx Security Group from CloudFormation
export SECURITY_GROUP=`aws cloudformation describe-stacks \
--stack-name $STACK_ID_VPC \
--query 'Stacks[0].Outputs[?OutputKey==\`SecurityGroup\`].OutputValue' \
--region ${AWS_REGION} \
--output text`
if [[ ! -z $SECURITY_GROUP ]]; then
echo "export SECURITY_GROUP=${SECURITY_GROUP}" >> env_vars
echo "[INFO] SECURITY_GROUP = ${SECURITY_GROUP}"
else
echo "[ERROR] failed to retrieve FSX Security Group"
return 1
fi
# Get sagemaker role ARN
export ROLE=`aws cloudformation describe-stacks \
--stack-name $STACK_ID_VPC \
--query 'Stacks[0].Outputs[?OutputKey==\`AmazonSagemakerClusterExecutionRoleArn\`].OutputValue' \
--region ${AWS_REGION} \
--output text`
if [[ ! -z $ROLE ]]; then
echo "export ROLE=${ROLE}" >> env_vars
echo "[INFO] ROLE = ${ROLE}"
else
echo "[ERROR] failed to retrieve Role ARN"
return 1
fi
# Get sagemaker role ROLENAME
export ROLENAME=$(basename "$ROLE")
if [[ ! -z $ROLENAME ]]; then
echo "export ROLENAME=${ROLENAME}" >> env_vars
echo "[INFO] ROLENAME = ${ROLENAME}"
else
echo "[ERROR] failed to retrieve Role NAME"
return 1
fi
# Get s3 bucket name
export BUCKET=`aws cloudformation describe-stacks \
--stack-name $STACK_ID_VPC \
--query 'Stacks[0].Outputs[?OutputKey==\`AmazonS3BucketName\`].OutputValue' \
--region ${AWS_REGION} \
--output text`
if [[ ! -z $BUCKET ]]; then
echo "export BUCKET=${BUCKET}" >> env_vars
echo "[INFO] BUCKET = ${BUCKET}"
else
echo "[ERROR] failed to retrieve Bucket Name"
return 1
fi