Skip to content

Commit 75c3c01

Browse files
author
Anubhav Sharma
committed
added pre-req scripts for Cloud9
1 parent b5eb36f commit 75c3c01

File tree

4 files changed

+248
-2
lines changed

4 files changed

+248
-2
lines changed

Cloud9Setup/increase-disk-size.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
# Specify the desired volume size in GiB as a command line argument. If not specified, default to 50 GiB.
4+
SIZE=50
5+
6+
# Get the ID of the environment host Amazon EC2 instance.
7+
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
8+
REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/\(.*\)[a-z]/\1/')
9+
10+
# Get the ID of the Amazon EBS volume associated with the instance.
11+
VOLUMEID=$(aws ec2 describe-instances \
12+
--instance-id $INSTANCEID \
13+
--query "Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId" \
14+
--output text \
15+
--region $REGION)
16+
17+
# Resize the EBS volume.
18+
aws ec2 modify-volume --volume-id $VOLUMEID --size $SIZE
19+
20+
# Wait for the resize to finish.
21+
while [ \
22+
"$(aws ec2 describe-volumes-modifications \
23+
--volume-id $VOLUMEID \
24+
--filters Name=modification-state,Values="optimizing","completed" \
25+
--query "length(VolumesModifications)"\
26+
--output text)" != "1" ]; do
27+
sleep 1
28+
done
29+
30+
#Check if we're on an NVMe filesystem
31+
if [[ -e "/dev/xvda" && $(readlink -f /dev/xvda) = "/dev/xvda" ]]
32+
then
33+
# Rewrite the partition table so that the partition takes up all the space that it can.
34+
sudo growpart /dev/xvda 1
35+
36+
# Expand the size of the file system.
37+
# Check if we're on AL2
38+
STR=$(cat /etc/os-release)
39+
SUB="VERSION_ID=\"2\""
40+
if [[ "$STR" == *"$SUB"* ]]
41+
then
42+
sudo xfs_growfs -d /
43+
else
44+
sudo resize2fs /dev/xvda1
45+
fi
46+
47+
else
48+
# Rewrite the partition table so that the partition takes up all the space that it can.
49+
sudo growpart /dev/nvme0n1 1
50+
51+
# Expand the size of the file system.
52+
# Check if we're on AL2
53+
STR=$(cat /etc/os-release)
54+
SUB="VERSION_ID=\"2\""
55+
if [[ "$STR" == *"$SUB"* ]]
56+
then
57+
sudo xfs_growfs -d /
58+
else
59+
sudo resize2fs /dev/nvme0n1p1
60+
fi
61+
fi
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
SUMMARY="Make sure all the pre-requisites checks PASS"$'\n'
3+
check_version() {
4+
retval=0
5+
MIN_VERSION=$1
6+
CURRENT_VERSION=$2
7+
IFS='.' read -r -a minarr <<< "$MIN_VERSION"
8+
IFS='.' read -r -a currarr <<< "$CURRENT_VERSION"
9+
10+
for ((i=0; i<${#minarr[@]}; i++));
11+
do
12+
#echo "${currarr[$i]}, ${minarr[$i]}"
13+
if [[ ${currarr[$i]} -gt ${minarr[$i]} ]]; then
14+
break
15+
elif [[ ${currarr[$i]} -lt ${minarr[$i]} ]]; then
16+
retval=1
17+
break
18+
else
19+
continue
20+
fi
21+
done
22+
23+
return $retval
24+
}
25+
26+
echo "Checking python version"
27+
python3 --version
28+
PYTHON_VERSION=$(python3 --version 2>&1 | cut -d'n' -f 2 | xargs)
29+
PYTHON_MIN_VERSION=3.8.0
30+
check_version $PYTHON_MIN_VERSION $PYTHON_VERSION
31+
if [[ $? -eq 1 ]]; then
32+
echo "ACTION REQUIRED: Need to have python version greater than or equal to $PYTHON_MIN_VERSION"
33+
SUMMARY+="* ACTION REQUIRED: Need to have python version greater than or equal to $PYTHON_MIN_VERSION"$'\n'
34+
else
35+
SUMMARY+="* PASS : Python version $PYTHON_VERSION installed. The minimum required version $PYTHON_MIN_VERSION"$'\n'
36+
fi
37+
echo ""
38+
39+
echo "Checking aws cli version"
40+
aws --version
41+
if [[ $? -ne 0 ]]; then
42+
echo "ACTION REQUIRED: aws cli is missing, please install !!"
43+
SUMMARY+="* ACTION REQUIRED: aws cli is missing, please install !!"$'\n'
44+
else
45+
AWS_VERSION=$(aws --version | cut -d'P' -f 1 | xargs)
46+
SUMMARY+="* PASS : $AWS_VERSION version installed"$'\n'
47+
jq --version
48+
if [[ $? -ne 0 ]]; then
49+
echo yes | sudo yum install jq
50+
fi
51+
CLOUD9_INSTANCE=$(aws ec2 describe-instances --filters Name=instance-type,Values=t3.large | jq -r '.Reservations[0].Instances[0].InstanceId')
52+
if [ -z $CLOUD9_INSTANCE ]; then
53+
echo "ACTION REQUIRED: Looks like Cloud9 instance with t3.large instance type is missing. Please create one!!"
54+
SUMMARY+="* ACTION REQUIRED: Looks like Cloud9 instance with t3.large instance type is missing. Please create one!!"$'\n'
55+
else
56+
SUMMARY+="* PASS : Has required t3.large instance type"$'\n'
57+
CLOUD9_INSTANCE_VOLUME_ID=$(aws ec2 describe-instances --filters Name=instance-type,Values=t3.large | jq -r '.Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId')
58+
VOLUME_SIZE=$(aws ec2 describe-volumes --volume-ids $CLOUD9_INSTANCE_VOLUME_ID | jq -r '.Volumes[0].Size')
59+
if [[ $VOLUME_SIZE -lt 50 ]]; then
60+
echo "ACTION REQUIRED: The volume size of cloud9 is less than 50GiB. Please update volume size to atleast 50GiB"
61+
SUMMARY+="* ACTION REQUIRED: The volume size of cloud9 is less than 50GiB. Please update volume size to atleast 50GiB"$'\n'
62+
else
63+
SUMMARY+="* PASS : Has minimum required 50GiB volume size"$'\n'
64+
fi
65+
fi
66+
fi
67+
echo ""
68+
69+
echo "Checking sam cli version"
70+
sam --version
71+
SAM_VERSION=$(sam --version | cut -d'n' -f 2 | xargs)
72+
SAM_MIN_VERSION=1.20.0
73+
check_version $SAM_MIN_VERSION $SAM_VERSION
74+
if [[ $? -eq 1 ]]; then
75+
echo "ACTION REQUIRED: Need to have SAM version greater than or equal to $SAM_MIN_VERSION"
76+
SUMMARY+="* ACTION REQUIRED: Need to have SAM version greater than or equal to $SAM_MIN_VERSION"$'\n'
77+
else
78+
SUMMARY+="* PASS : Sam cli version $SAM_VERSION installed. The minimum required version $SAM_MIN_VERSION"$'\n'
79+
fi
80+
echo ""
81+
82+
echo "Checking git-remote-codecommit version"
83+
python3 -m pip show git-remote-codecommit
84+
if [[ $? -ne 0 ]]; then
85+
echo "ACTION REQUIRED: git-remote-codecommit is missing, please install"
86+
SUMMARY+="* ACTION REQUIRED: git-remote-codecommit is missing, please install !!"$'\n'
87+
else
88+
SUMMARY+="* PASS : Has git-remote-codecommit installed"$'\n'
89+
fi
90+
echo ""
91+
92+
echo "Checking node version"
93+
node --version
94+
NODE_VERSION=$(node --version | cut -d'v' -f 2)
95+
NODE_MIN_VERSION=14.0.0
96+
check_version $NODE_MIN_VERSION $NODE_VERSION
97+
if [[ $? -eq 1 ]]; then
98+
echo "ACTION REQUIRED: Need to have Node version greater than or equal to $NODE_MIN_VERSION"
99+
SUMMARY+="* ACTION REQUIRED: Need to have Node version greater than or equal to $NODE_MIN_VERSION"$'\n'
100+
else
101+
SUMMARY+="* PASS : Node version $NODE_VERSION installed. The minimum required version $NODE_MIN_VERSION"$'\n'
102+
fi
103+
echo ""
104+
105+
106+
echo "Checking cdk version"
107+
cdk --version
108+
CDK_VERSION=$(cdk --version | cut -d'(' -f 1| xargs)
109+
CDK_MIN_VERSION=2.40.0
110+
check_version $CDK_MIN_VERSION $CDK_VERSION
111+
if [[ $? -eq 1 ]]; then
112+
echo "ACTION REQUIRED: Need to have CDK version greater than or equal to $CDK_MIN_VERSION"
113+
SUMMARY+="* ACTION REQUIRED: Need to have CDK version greater than or equal to $CDK_MIN_VERSION"$'\n'
114+
else
115+
SUMMARY+="* PASS : CDK version $CDK_VERSION installed. The minimum required version $CDK_MIN_VERSION"$'\n'
116+
fi
117+
echo ""
118+
119+
echo "***************SUMMARY****************"
120+
echo "$SUMMARY"
121+
echo "***************END OF SUMMARY*********"

Cloud9Setup/pre-requisites.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash -x
2+
. /home/ec2-user/.nvm/nvm.sh
3+
4+
#Install python3.8
5+
sudo yum install -y amazon-linux-extras
6+
sudo amazon-linux-extras enable python3.8
7+
sudo yum install -y python3.8
8+
sudo alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
9+
sudo alternatives --set python3 /usr/bin/python3.8
10+
11+
# Uninstall aws cli v1 and Install aws cli version-2.3.0
12+
sudo pip2 uninstall awscli -y
13+
14+
echo "Installing aws cli version-2.3.0"
15+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.3.0.zip" -o "awscliv2.zip"
16+
unzip awscliv2.zip
17+
sudo ./aws/install
18+
rm awscliv2.zip
19+
rm -rf aws
20+
21+
# Install sam cli version 1.33.0
22+
echo "Installing sam cli version 1.33.0"
23+
wget https://github.com/aws/aws-sam-cli/releases/download/v1.33.0/aws-sam-cli-linux-x86_64.zip
24+
unzip aws-sam-cli-linux-x86_64.zip -d sam-installation
25+
sudo ./sam-installation/install
26+
if [ $? -ne 0 ]; then
27+
echo "Sam cli is already present, so deleting existing version"
28+
sudo rm /usr/local/bin/sam
29+
sudo rm -rf /usr/local/aws-sam-cli
30+
echo "Now installing sam cli version 1.33.0"
31+
sudo ./sam-installation/install
32+
fi
33+
rm aws-sam-cli-linux-x86_64.zip
34+
rm -rf sam-installation
35+
36+
# Install git-remote-codecommit version 1.15.1
37+
echo "Installing git-remote-codecommit version 1.15.1"
38+
curl -O https://bootstrap.pypa.io/get-pip.py
39+
python3 get-pip.py --user
40+
rm get-pip.py
41+
42+
python3 -m pip install git-remote-codecommit==1.15.1
43+
44+
# Install node v14.18.1
45+
echo "Installing node v14.18.1"
46+
nvm deactivate
47+
nvm uninstall node
48+
nvm install v14.18.1
49+
nvm use v14.18.1
50+
nvm alias default v14.18.1
51+
52+
# Install cdk cli version ^2.0.0
53+
echo "Installing cdk cli version ^2.0.0"
54+
npm uninstall -g aws-cdk
55+
npm install -g aws-cdk@"^2.0.0"
56+
57+
#Install jq version 1.5
58+
sudo yum -y install jq-1.5
59+
60+
#Install pylint version 2.11.1
61+
python3 -m pip install pylint==2.11.1

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ Figure 1 provides a high-level representation of the baseline architecture that
1818
<p align="center"><img src="images/Baseline.png" alt="Baseline Infrastructure"/>Figure 1: Baseline infrastructure</p>
1919

2020
## Pre-requisites
21+
22+
NOTE: If you are using Cloud9 to deploy the architecture, then make sure that to select at least t3.large instance size and increase the volume size of the underlying EC2 instance to 50 GB (instead of default 10 GB). This is to make sure that you have enough compute and space to build the solution.
23+
24+
You can also use the scripts under "Cloud9Setup" folder to increase disk size and install pre-requisites inside your Cloud9 environment.
25+
2126
* This reference architecture uses Python. Make sure you have Python 3.8 Installed.
2227
* Make sure you have [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) Installed.
2328
* Make sure you have the latest version of [AWS SAM](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) installed. Not having the release version of SAM can cause deployment issues.
@@ -27,8 +32,6 @@ Figure 1 provides a high-level representation of the baseline architecture that
2732

2833
## Setting up the environment
2934

30-
NOTE: If you are using Cloud9 to deploy the architecture, then make sure that to select at least t3.large instance size and increase the volume size of the underlying EC2 instance to 50 GB (instead of default 10 GB). This is to make sure that you have enough compute and space to build the solution.
31-
3235
Run the below script to deploy the required component. Replace the "[email protected]" email address with yours. This email address is used to setup an admin user in the architecture.
3336

3437
```bash

0 commit comments

Comments
 (0)