Skip to content

Commit 7afbd06

Browse files
authored
Merge pull request #131 from ravigurram8/topic-release-11
1.17.0 build updates
2 parents 7d0499c + 4d5f849 commit 7afbd06

55 files changed

Lines changed: 409 additions & 23 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cft-templates/sagemaker-template-with-url.yml

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ Description: 'AWS CloudFormation Sample Template SageMaker NotebookInstance: Thi
55
the creation of a SageMaker NotebookInstance with encryption. You will be billed for the AWS resources used if you create a stack from
66
this template. (fdp-1qj64b3fd)'
77
Parameters:
8+
Namespace:
9+
Type: String
10+
Description: An environment name that will be prefixed to resource names
11+
S3Mounts:
12+
Type: String
13+
Description: A JSON array of objects with name, bucket and prefix properties used to mount data
14+
IamPolicyDocument:
15+
Type: String
16+
Description: The IAM policy to be associated with the launched workstation
17+
EnvironmentInstanceFiles:
18+
Type: String
19+
Description: >-
20+
An S3 URI (starting with "s3://") that specifies the location of files to be copied to
21+
the environment instance, including any bootstrap scripts
822
NotebookInstanceType:
923
AllowedValues:
1024
- ml.t2.medium
@@ -21,10 +35,15 @@ Parameters:
2135
Default: ml.t3.medium
2236
Description: Select Instance type for the SageMaker Notebook. e.g.ml.t3.medium
2337
Type: String
38+
Conditions:
39+
IamPolicyEmpty: !Equals [!Ref IamPolicyDocument, '{}']
40+
2441
Resources:
25-
SageMakerRole:
42+
IAMRole:
2643
Type: AWS::IAM::Role
2744
Properties:
45+
RoleName: !Join ['-', [Ref: Namespace, 'sagemaker-notebook-role']]
46+
Path: '/'
2847
AssumeRolePolicyDocument:
2948
Version: 2012-10-17
3049
Statement:
@@ -34,6 +53,12 @@ Resources:
3453
- "sagemaker.amazonaws.com"
3554
Action:
3655
- "sts:AssumeRole"
56+
Policies:
57+
- !If
58+
- IamPolicyEmpty
59+
- !Ref 'AWS::NoValue'
60+
- PolicyName: !Join ['-', [Ref: Namespace, 's3-studydata-policy']]
61+
PolicyDocument: !Ref IamPolicyDocument
3762
ManagedPolicyArns:
3863
- "arn:aws:iam::aws:policy/AmazonSageMakerFullAccess"
3964
- "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
@@ -42,8 +67,8 @@ Resources:
4267
Type: "AWS::SageMaker::NotebookInstance"
4368
Properties:
4469
InstanceType: !Ref NotebookInstanceType
45-
RoleArn: !GetAtt SageMakerRole.Arn
46-
PlatformIdentifier: notebook-al2-v2
70+
RoleArn: !GetAtt IAMRole.Arn
71+
PlatformIdentifier: notebook-al2-v1
4772
LifecycleConfigName: !GetAtt NotebookLifeCycleConfig.NotebookInstanceLifecycleConfigName
4873
Tags:
4974
- Key: cost_resource
@@ -57,10 +82,11 @@ Resources:
5782
OnStart:
5883
- Content:
5984
Fn::Base64: !Sub |
60-
#!/bin/bash
61-
62-
set -e
63-
85+
#!/usr/bin/env bash
86+
aws s3 cp "${EnvironmentInstanceFiles}/get_bootstrap.sh" "/tmp"
87+
chmod 500 "/tmp/get_bootstrap.sh"
88+
/tmp/get_bootstrap.sh "${EnvironmentInstanceFiles}" '${S3Mounts}'
89+
6490
function get_tag()
6591
{
6692

@@ -80,7 +106,6 @@ Resources:
80106
echo "export 'DATA_BUCKET'=$DATA_BUCKET" >> /etc/profile.d/jupyter-env.sh
81107
fi
82108

83-
84109
#Copy Sample notebook from S3
85110

86111
TEMPLATE_NOTEBOOK_BUCKET=$(get_tag "TEMPLATE_NOTEBOOK_BUCKET")
@@ -98,12 +123,13 @@ Resources:
98123

99124
systemctl restart jupyter-server
100125

101-
102-
103126
Outputs:
104127
SageMakerNotebookInstanceARN:
105128
Description: "ARN for the newly created SageMaker Notebook Instance"
106129
Value: !Ref SageMakerNotebookInstance
107130
NotebookInstanceName:
108131
Description: "Name for the newly created SageMaker Notebook Instance"
109-
Value: !GetAtt [SageMakerNotebookInstance, NotebookInstanceName]
132+
Value: !GetAtt [SageMakerNotebookInstance, NotebookInstanceName]
133+
WorkspaceInstanceRoleArn:
134+
Description: IAM role assumed by the SageMaker workspace instance
135+
Value: !GetAtt IAMRole.Arn

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ services:
1818
- sp2net
1919

2020
cc-3102:
21-
image: 045938549113.dkr.ecr.us-east-2.amazonaws.com/researchportal:_fd_1.16.0_b1600
21+
image: 045938549113.dkr.ecr.us-east-2.amazonaws.com/researchportal:_fd_1.17.0_b1675
2222
secrets:
2323
- source: sp2prod-config.json
2424
target: /rlc/cc/server/app/config/config.json
@@ -42,7 +42,7 @@ services:
4242

4343

4444
scheduler-3102:
45-
image: 045938549113.dkr.ecr.us-east-2.amazonaws.com/researchportal:_fd_1.16.0_b1600
45+
image: 045938549113.dkr.ecr.us-east-2.amazonaws.com/researchportal:_fd_1.17.0_b1675
4646
secrets:
4747
- source: sp2prod-config.json
4848
target: /rlc/cc/server/app/config/config.json

dump/configs.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
},
225225
"key": "projectStorage",
226226
"value": {
227-
"productList": ["ec2", "rstudio", "nextflow", "cromwell", "ec2-dcv"],
227+
"productList": ["ec2", "rstudio", "nextflow", "cromwell", "ec2-dcv", "sagemaker"],
228228
"s3Mounts": {
229229
"ProjectStorage": {
230230
"id": "ProjectStorage",
@@ -404,10 +404,11 @@
404404
"ec2",
405405
"rstudio",
406406
"nextflow",
407-
"cromwell"
407+
"cromwell",
408+
"sagemaker"
408409
]
409410
},
410-
"studySelectionCount" : 4
411+
"studySelectionCount" : 5.0
411412
},
412413
{
413414
"_id" : {

dump/standardcatalogitems.json

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,29 @@
254254
"availableRegions": [],
255255
"assignedOU": [],
256256
"metaData": {
257-
"pre_provisioning": [],
257+
"pre_provisioning": [
258+
{
259+
"code" : "CFT_PARAMS",
260+
"params" : [
261+
{
262+
"name" : "EnvironmentInstanceFiles",
263+
"type" : "RL::SC::PARAM::HD"
264+
},
265+
{
266+
"name" : "IamPolicyDocument",
267+
"type" : "RL::SC::PARAM::HD"
268+
},
269+
{
270+
"name" : "S3Mounts",
271+
"type" : "RL::SC::PARAM::HD"
272+
},
273+
{
274+
"name" : "Namespace",
275+
"type" : "RL::SC::PARAM::HD"
276+
}
277+
]
278+
}
279+
],
258280
"post_provisioning": [],
259281
"checks_before_assigning_product": [],
260282
"checks_after_assigning_product": [],

packer-rg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"awsRegion": "",
77
"RG_HOME": "/opt/deploy/sp2",
88
"RG_SRC": "/home/ubuntu",
9-
"amiName": "RG-AMI-1.16.0"
9+
"amiName": "RG-AMI-1.17.0"
1010
},
1111
"builders": [
1212
{

provisioners/provision-ecr.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash -xe
22
sudo docker login -u AWS -p $(aws ecr get-login-password --region us-east-2) 045938549113.dkr.ecr.us-east-2.amazonaws.com
3-
sudo docker pull 045938549113.dkr.ecr.us-east-2.amazonaws.com/researchportal:_fd_1.16.0_b1600
3+
sudo docker pull 045938549113.dkr.ecr.us-east-2.amazonaws.com/researchportal:_fd_1.17.0_b1675
44
sudo docker pull 045938549113.dkr.ecr.us-east-2.amazonaws.com/nginx:latest
55
sudo docker pull 045938549113.dkr.ecr.us-east-2.amazonaws.com/notificationsink:1.15.0_b1

scripts/bootstrap-scripts/bin/mount_s3.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ AWS_CONFIG_DIR="${HOME}/.aws"
1717
# Exit if CONFIG doesn't exist or is 0 bytes
1818
[ ! -s "$CONFIG" ] && exit 0
1919

20+
# Define a function to determine what type of environment this is (EMR, SageMaker, RStudio, or EC2 Linux)
21+
env_type() {
22+
if [ -d "/home/ec2-user/SageMaker" ]
23+
then
24+
printf "sagemaker"
25+
fi
26+
}
27+
2028
# Add roleArn for a study to credentials file if not present already
2129
append_role_to_credentials() {
2230
study_id=$1
@@ -32,6 +40,7 @@ append_role_to_credentials() {
3240
fi
3341
}
3442

43+
export AWS_SDK_LOAD_CONFIG=1
3544
# Mount S3 buckets
3645
mounts="$(cat "$CONFIG")"
3746
num_mounts=$(printf "%s" "$mounts" | jq ". | length" -)
@@ -73,3 +82,21 @@ do
7382
fi
7483
fi
7584
done
85+
86+
# Define where the Jupyter notebook (if any) should be running
87+
notebook_dir=""
88+
case "$(env_type)" in
89+
"sagemaker")
90+
notebook_dir="/home/ec2-user/SageMaker"
91+
;;
92+
esac
93+
94+
# Add a link to the mount in the notebook directory.
95+
# (The user gets easy access, but it won't check the bucket into a git repo.)
96+
# Only create a link if Jupyter is running, there are studies mounted, and the link
97+
# doesn't already exist.
98+
if [ -n "$notebook_dir" -a $num_mounts -ne 0 ]
99+
then
100+
symlink_name="$notebook_dir/studies"
101+
[ ! -L "$symlink_name" ] && sudo ln -s "$MOUNT_DIR" "$symlink_name"
102+
fi

scripts/bootstrap-scripts/bootstrap.sh

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RSTUDIO_USER="$2"
1414

1515
# Get directory in which this script is stored and define URL from which to download goofys
1616
FILES_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
17-
GOOFYS_URL="https://github.com/kahing/goofys/releases/download/v0.21.0/goofys"
17+
GOOFYS_URL="https://github.com/kahing/goofys/releases/download/v0.24.0/goofys"
1818

1919
# Define a function to determine what type of environment this is (RStudio, or EC2 Linux)
2020
env_type() {
@@ -24,23 +24,74 @@ env_type() {
2424
elif [ -f "/usr/bin/nextflow" ]
2525
then
2626
printf "nextflow"
27+
elif [ -d "/home/ec2-user/SageMaker" ]
28+
then
29+
printf "sagemaker"
2730
else
2831
printf "ec2-linux"
2932
fi
3033
}
3134

35+
# Define a function to update Jupyter configuration files
36+
update_jupyter_config() {
37+
38+
config_file="$1"
39+
40+
# HACK: Update the default SessionManager class used by Jupyter notebooks
41+
# so that it runs the S3 mount script the first time sessions are listed
42+
cat << EOF | cut -b5- >> "$config_file"
43+
44+
import subprocess
45+
from notebook.services.sessions.sessionmanager import SessionManager as BaseSessionManager
46+
47+
class SessionManager(BaseSessionManager):
48+
def list_sessions(self, *args, **kwargs):
49+
"""Override default list_sessions() method"""
50+
self.mount_studies()
51+
result = super(SessionManager, self).list_sessions(*args, **kwargs)
52+
return result
53+
54+
def mount_studies(self):
55+
"""Execute mount_s3.sh if it hasn't already been run"""
56+
if not hasattr(self, 'studies_mounted'):
57+
mounting_result = subprocess.run(
58+
"mount_s3.sh",
59+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT
60+
)
61+
62+
# Log results
63+
if mounting_result.stdout:
64+
for line in mounting_result.stdout.decode("utf-8").split("\n"):
65+
if line: # Skip empty lines
66+
self.log.info(line)
67+
68+
self.studies_mounted = True
69+
70+
c.NotebookApp.session_manager_class = SessionManager
71+
EOF
72+
}
73+
3274
# Install dependencies
33-
yum install -y jq-1.5
34-
curl -LSs -o "/usr/local/bin/goofys" "$GOOFYS_URL"
75+
echo "Installing JQ"
76+
sudo mv "${FILES_DIR}/offline-packages/jq-1.5-linux64" "/usr/local/bin/jq"
77+
chmod +x "/usr/local/bin/jq"
78+
echo "Finish installing jq"
79+
80+
echo "Copying Goofys from bootstrap.sh"
81+
cp "${FILES_DIR}/offline-packages/goofys" /usr/local/bin/goofys
3582
chmod +x "/usr/local/bin/goofys"
3683

3784
# Install ec2 instance connect agent
3885
sudo yum install ec2-instance-connect-1.1
3986

4087
# Create S3 mount script and config file
88+
echo "Mounting S3"
4189
chmod +x "${FILES_DIR}/bin/mount_s3.sh"
4290
ln -s "${FILES_DIR}/bin/mount_s3.sh" "/usr/local/bin/mount_s3.sh"
4391
printf "%s" "$S3_MOUNTS" > "/usr/local/etc/s3-mounts.json"
92+
echo "Finish mounting S3"
93+
94+
OS_VERSION=`cat /etc/os-release | grep VERSION= | sed 's/VERSION="//' | sed 's/"//'`
4495

4596
# Apply updates to environments based on environment type
4697
case "$(env_type)" in
@@ -56,6 +107,31 @@ case "$(env_type)" in
56107
yum install -y fuse-2.9.2
57108
printf "\n# Mount S3 study data\nmount_s3.sh\n\n" >> "/home/ec2-user/.bash_profile"
58109
;;
110+
"sagemaker") # Update config and restart Jupyter
111+
if [ $OS_VERSION = '2' ]
112+
then
113+
echo "Installing fuse for AL2"
114+
cd "${FILES_DIR}/offline-packages/sagemaker/fuse-2.9.4_AL2"
115+
sudo yum --disablerepo=* localinstall -y *.rpm
116+
echo "Finish installing fuse"
117+
echo "Installing boto3 for AL2"
118+
cd "${FILES_DIR}/offline-packages/sagemaker/boto3"
119+
sudo yum --disablerepo=* localinstall -y python2-boto3-1.4.4-1.amzn2.noarch.rpm
120+
echo "Finish installing boto3"
121+
else
122+
echo "Installing fuse for AL1"
123+
cd "${FILES_DIR}/offline-packages/sagemaker/fuse-2.9.4"
124+
sudo yum --disablerepo=* localinstall -y *.rpm
125+
echo "Finish installing fuse"
126+
fi
127+
update_jupyter_config "/home/ec2-user/.jupyter/jupyter_notebook_config.py"
128+
if [ $OS_VERSION = '2' ]
129+
then
130+
systemctl restart jupyter-server
131+
else
132+
initctl restart jupyter-server --no-wait
133+
fi
134+
;;
59135
esac
60136

61137
exit 0
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
# This script bootstraps a workspace instance by preparing S3 study data to be
4+
# mounted via the mount_s3.sh environment script.
5+
# Note that mounting cannot be performed during initial bootstrapping
6+
# because the instance's role will not yet have access to S3 study
7+
# data since the associated resource policies aren't updated until after the
8+
# CFN stack has been completed created.
9+
S3_MOUNTS="$1"
10+
11+
# Exit if no S3 mounts were specified
12+
[ -z "$S3_MOUNTS" ] || [ "$S3_MOUNTS" = "[]" ] && exit 0
13+
14+
# Get directory in which this script is stored and define URL from which to download goofys
15+
FILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
16+
GOOFYS_URL="https://github.com/kahing/goofys/releases/download/v0.21.0/goofys"
17+
18+
# Install dependencies
19+
apt-get install jq=1.6-1ubuntu0.20.04.1
20+
curl -LSs -o "/usr/local/bin/goofys" "$GOOFYS_URL"
21+
chmod +x "/usr/local/bin/goofys"
22+
23+
# Install ec2 instance connect agent
24+
apt-get install ec2-instance-connect=1.1.12+dfsg1-0ubuntu3.20.04.1
25+
26+
# Create S3 mount script and config file
27+
chmod +x "${FILES_DIR}/bin/mount_s3.sh"
28+
ln -s "${FILES_DIR}/bin/mount_s3.sh" "/usr/local/bin/mount_s3.sh"
29+
printf "%s" "$S3_MOUNTS" >"/usr/local/etc/s3-mounts.json"
30+
apt-get install fuse=2.9.9-3
31+
printf "\n# Mount S3 study data\nmount_s3.sh\n\n" >>"/home/ubuntu/.bash_profile"
32+
printf "\nif [ -f /home/ubuntu/.bashrc ]; then\n\t. /home/ubuntu/.bashrc\nfi " >>"/home/ubuntu/.bash_profile"
33+
printf 'export PATH=/usr/local/src/bowtie2-2.2.9:$PATH' >>"/home/ubuntu/.bashrc"
34+
chown ubuntu:ubuntu /home/ubuntu/.bashrc
35+
chown ubuntu:ubuntu /home/ubuntu/.bash_profile
36+
exit 0

0 commit comments

Comments
 (0)