Skip to content

Commit 3faee64

Browse files
Merge branch 'topic-release' into topic-release
2 parents 3047afb + 4b6d6e2 commit 3faee64

45 files changed

Lines changed: 3781 additions & 1105 deletions

Some content is hidden

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

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.vscode
2+
*.tar.gz
3+
rg-deployment-docs
4+
rg-cft-templates
5+
.trunk
6+
.trunk/*
7+
.isort.cfg
8+
.markdownlint.yaml
9+
.flake8
10+
.shellcheckrc

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ If an AMI with the pre-requisites has been shared with you, you can skip this se
6969

7070
You can create the AMI with pre-requisites yourself by following these steps:
7171
- Install packer
72-
- Create a Role and attach a policy which permits ECR and EC2 actions and Replace it in builders section
7372
- Export AWS Access Keys and Secret Keys
7473
- export AWS_ACCESS_KEY_ID="your_Access_Key"
7574
- export AWS_SECRET_ACCESS_KEY="your_Secret_Key"
7675
- export AWS_DEFAULT_REGION="Your_Region"
77-
- Download dump.tar.gz to your local rdeploy folder from s3://rg-deployment-docs
78-
- Run packer build package-rg.json.
76+
- Clone this repo on a machine.
77+
- Create a Role and attach a policy which permits ECR and EC2 actions and Replace the "iam-instance_profile" :"<your_rolename>" in builders section which is in the packer-rg.json.
78+
- Run packer build packer-rg.json
7979
- packer build -var 'awsRegion=your_region' -var 'vpcId=your_VPCID' -var 'subnetId=your_SubnetID' packer-rg.json
8080
- At Run time pass VPCID, SubnetID, AWSRegion as variables declared in packer-rg.json
8181
- Note that AMI id from the output

cft-templates/Rstudio.yml

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
AWSTemplateFormatVersion: 2010-09-09
1+
AWSTemplateFormatVersion: '2010-09-09'
22

33
Description: Sets up RStudio environment on AWS
44

55
Parameters:
6+
Namespace:
7+
Type: String
8+
Description: An environment name that will be prefixed to resource names
9+
S3Mounts:
10+
Type: String
11+
Description: A JSON array of objects with name, bucket, and prefix properties used to mount data
12+
IamPolicyDocument:
13+
Type: String
14+
Description: The IAM policy to be associated with the launched workstation
15+
EnvironmentInstanceFiles:
16+
Type: String
17+
Description: >-
18+
An S3 URI (starting with "s3://") that specifies the location of files to be copied to
19+
the environment instance, including any bootstrap scripts
620
InstanceType:
721
Type: String
822
Description: Instance type for RStudio. Default is t2.medium.
@@ -30,7 +44,39 @@ Parameters:
3044
Type: "AWS::EC2::KeyPair::KeyName"
3145
Description: Name of an existing EC2 KeyPair to enable SSH access to the instance. If no key pairs exist, please create one from the button next to the dropdown. Please contact your Administrator if you are unable to create one.
3246

47+
Conditions:
48+
IamPolicyEmpty: !Equals [!Ref IamPolicyDocument, '{}']
49+
3350
Resources:
51+
IAMRole:
52+
Type: 'AWS::IAM::Role'
53+
Properties:
54+
RoleName: !Join ['-', [Ref: Namespace, 'rstudio-role']]
55+
Path: '/'
56+
AssumeRolePolicyDocument:
57+
Version: '2012-10-17'
58+
Statement:
59+
- Effect: 'Allow'
60+
Principal:
61+
Service:
62+
- 'ec2.amazonaws.com'
63+
Action:
64+
- 'sts:AssumeRole'
65+
Policies:
66+
- !If
67+
- IamPolicyEmpty
68+
- !Ref 'AWS::NoValue'
69+
- PolicyName: !Join ['-', [Ref: Namespace, 's3-studydata-policy']]
70+
PolicyDocument: !Ref IamPolicyDocument
71+
72+
InstanceProfile:
73+
Type: 'AWS::IAM::InstanceProfile'
74+
Properties:
75+
InstanceProfileName: !Join ['-', [Ref: Namespace, 'rstudio-profile']]
76+
Path: '/'
77+
Roles:
78+
- Ref: IAMRole
79+
3480
RstudioEC2SecurityGroup:
3581
Type: AWS::EC2::SecurityGroup
3682
Properties:
@@ -53,30 +99,37 @@ Resources:
5399
Type: AWS::EC2::Instance
54100
CreationPolicy:
55101
ResourceSignal:
56-
Timeout: PT9M
102+
Timeout: PT10M
57103
Properties:
58104
ImageId : '{{resolve:ssm:/RL/RG/StandardCatalog/RStudio}}'
59105
InstanceType: !Ref 'InstanceType'
60106
SecurityGroups: [!Ref 'RstudioEC2SecurityGroup']
61107
KeyName: !Ref 'KeyPair'
62-
UserData: !Base64
108+
IamInstanceProfile: !Ref InstanceProfile
63109
Tags:
64-
- Key: Name
65-
Value: !Join ["-", [!Ref "AWS::StackName", "RStudio"]]
110+
- Key: Name
111+
Value: !Join ['-', [Ref: Namespace, 'rstudio-server']]
112+
- Key: Description
113+
Value: EC2 linux based Rstudio server
66114
UserData:
67115
Fn::Base64: !Sub |
68116
#!/bin/bash
69117
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
70118
trap '/opt/aws/bin/cfn-signal --exit-code 1 --resource RstudioEC2Instance --region ${AWS::Region} --stack ${AWS::StackName}' ERR
119+
sudo yum update -y --security
120+
71121
#add user(s)
72122
sudo useradd -m -s /bin/bash ${InitialUser}
73123
sudo echo ${InitialUser}:${InitialPassword} | chpasswd
74-
/opt/aws/bin/cfn-signal --exit-code 0 --resource RstudioEC2Instance --region ${AWS::Region} --stack ${AWS::StackName}
124+
125+
#Download and execute bootstrap script
126+
aws s3 cp "${EnvironmentInstanceFiles}/get_bootstrap.sh" "/tmp"
127+
chmod 500 "/tmp/get_bootstrap.sh"
128+
/tmp/get_bootstrap.sh "${EnvironmentInstanceFiles}" '${S3Mounts}'
129+
130+
/opt/aws/bin/cfn-signal --exit-code 0 --resource RstudioEC2Instance --region ${AWS::Region} --stack ${AWS::StackName}
75131

76132
Outputs:
77-
RStudioURL:
78-
Value: !GetAtt RstudioEC2Instance.PublicDnsName
79-
Description: URL to Access RStudio
80133
InstanceDNSName:
81134
Value: !GetAtt RstudioEC2Instance.PublicDnsName
82135
Description: Public DNS Name
@@ -85,4 +138,4 @@ Outputs:
85138
InstanceId:
86139
Value: !Ref 'RstudioEC2Instance'
87140
ApplicationPort:
88-
Value: '8787'
141+
Value: '8787'

cft-templates/ec2-EIP.yml

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
Metadata:
22
License: Apache-2.0
33
AWSTemplateFormatVersion: '2010-09-09'
4-
Description: 'AWS CloudFormation Sample Template Sample template EIP_With_Association:
5-
This template shows how to associate an Elastic IP address with an Amazon EC2 instance
6-
- you can use this same technique to associate an EC2 instance with an Elastic IP
7-
Address that is not created inside the template by replacing the EIP reference in
8-
the AWS::EC2::EIPAssoication resource type with the IP address of the external EIP.
4+
Description: 'AWS CloudFormation Template to create an EC2 instance
95
**WARNING** This template creates an Amazon EC2 instance and an Elastic IP Address.
106
You will be billed for the AWS resources used if you create a stack from this template.'
7+
118
Parameters:
9+
Namespace:
10+
Type: String
11+
Description: An environment name that will be prefixed to resource names
12+
S3Mounts:
13+
Type: String
14+
Description: A JSON array of objects with name, bucket, and prefix properties used to mount data
15+
IamPolicyDocument:
16+
Type: String
17+
Description: The IAM policy to be associated with the launched workstation
18+
EnvironmentInstanceFiles:
19+
Type: String
20+
Description: >-
21+
An S3 URI (starting with "s3://") that specifies the location of files to be copied to
22+
the environment instance, including any bootstrap scripts
1223
InstanceType:
1324
Description: Choose the instance type for this instance. e.g. t2.small
1425
Type: String
@@ -30,15 +41,65 @@ Parameters:
3041
LatestAmiId:
3142
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
3243
Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'
33-
Resources:
44+
45+
Conditions:
46+
IamPolicyEmpty: !Equals [!Ref IamPolicyDocument, '{}']
47+
48+
Resources:
49+
IAMRole:
50+
Type: 'AWS::IAM::Role'
51+
Properties:
52+
RoleName: !Join ['-', [Ref: Namespace, 'ec2-role']]
53+
Path: '/'
54+
AssumeRolePolicyDocument:
55+
Version: '2012-10-17'
56+
Statement:
57+
- Effect: 'Allow'
58+
Principal:
59+
Service:
60+
- 'ec2.amazonaws.com'
61+
Action:
62+
- 'sts:AssumeRole'
63+
Policies:
64+
- !If
65+
- IamPolicyEmpty
66+
- !Ref 'AWS::NoValue'
67+
- PolicyName: !Join ['-', [Ref: Namespace, 's3-studydata-policy']]
68+
PolicyDocument: !Ref IamPolicyDocument
69+
70+
InstanceProfile:
71+
Type: 'AWS::IAM::InstanceProfile'
72+
Properties:
73+
InstanceProfileName: !Join ['-', [Ref: Namespace, 'ec2-profile']]
74+
Path: '/'
75+
Roles:
76+
- Ref: IAMRole
77+
3478
EC2Instance:
3579
Type: AWS::EC2::Instance
3680
Properties:
37-
UserData: !Base64
81+
UserData:
82+
Fn::Base64: !Sub |
83+
#!/usr/bin/env bash
84+
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
85+
# Download and execute bootstrap script
86+
aws s3 cp "${EnvironmentInstanceFiles}/get_bootstrap.sh" "/tmp"
87+
chmod 500 "/tmp/get_bootstrap.sh"
88+
/tmp/get_bootstrap.sh "${EnvironmentInstanceFiles}" '${S3Mounts}'
89+
90+
# Signal result to CloudFormation
91+
/opt/aws/bin/cfn-signal -e $? --stack "${AWS::StackName}" --resource "EC2Instance" --region "${AWS::Region}"
3892
InstanceType: !Ref 'InstanceType'
3993
SecurityGroups: [!Ref 'InstanceSecurityGroup']
4094
KeyName: !Ref 'KeyPair'
4195
ImageId: !Ref 'LatestAmiId'
96+
IamInstanceProfile: !Ref InstanceProfile
97+
Tags:
98+
- Key: Name
99+
Value: !Join ['-', [Ref: Namespace, 'ec2-linux']]
100+
- Key: Description
101+
Value: EC2 workspace instance
102+
42103
InstanceSecurityGroup:
43104
Type: AWS::EC2::SecurityGroup
44105
Properties:
@@ -48,6 +109,7 @@ Resources:
48109
FromPort: '22'
49110
ToPort: '22'
50111
CidrIp: !Ref 'AllowedSSHLocation'
112+
51113
Outputs:
52114
InstanceId:
53115
Description: InstanceId of the newly created EC2 instance
@@ -57,4 +119,4 @@ Outputs:
57119
Value: !GetAtt [EC2Instance, PublicIp]
58120
InstanceDNSName:
59121
Description: DNS name of the newly created EC2 instance
60-
Value: !GetAtt [EC2Instance, PublicDnsName]
122+
Value: !GetAtt [EC2Instance, PublicDnsName]

cft-templates/nextflow-advanced.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,17 @@ Resources:
542542
UserData:
543543
Fn::Base64: !Sub |
544544
#!/bin/bash -xe
545+
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
545546

546547
sudo yum update -y --security
547-
cd /root/
548+
cd /root/
548549

549550
getOutputData=${OutputDataLocation}
550551
getFirstChar=`echo $getOutputData | cut -c1-1`
551552

552553
if [ "$getFirstChar" == "/" ]
553554
then :
554-
echo "Ngnix URL"
555+
echo "Ngnix URL"
555556
OutputDataLocation=${OutputDataLocation}
556557
echo $OutputDataLocation
557558
else

config/app-config.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
var mkdirp = require('mkdirp');
2-
var fs = require('fs');
1+
var mkdirp = require("mkdirp");
2+
var fs = require("fs");
33
var currentDirectory = __dirname;
4-
var logger = require('../logger/logger')(module);
4+
var logger = require("../logger/logger")(module);
55

66
var configJson;
77
try {
8-
configJson = fs.readFileSync(currentDirectory + '/dashboard-settings.json', {
9-
'encoding': 'utf8'
10-
});
8+
configJson = fs.readFileSync(currentDirectory + "/config.json", {
9+
encoding: "utf8",
10+
});
1111
} catch (err) {
12-
logger.error(err);
13-
configJson = null;
14-
throw err;
12+
logger.error(err);
13+
configJson = null;
14+
throw err;
1515
}
1616

1717
if (configJson) {
18-
var config = JSON.parse(configJson);
18+
var config = JSON.parse(configJson);
1919
}
2020

2121
mkdirp.sync(config.tempDashboardHome);
2222
mkdirp.sync(config.dashboardHome);
2323

2424
module.exports = config;
25-

config/bucket-policy.json

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,62 @@
1-
{
2-
"Sid": "id-1",
3-
"Effect": "Allow",
4-
"Principal": {
5-
"AWS": ""
6-
},
7-
"Action": "s3:GetObject",
8-
"Resource": "arn:aws:s3:::REPLACE-WITH-S3-BUCKET-NAME/*"
9-
}
1+
[
2+
{
3+
"Sid": "Get:Artifacts",
4+
"Effect": "Allow",
5+
"Principal": {
6+
"AWS": "{principalArns}"
7+
},
8+
"Action": "s3:GetObject",
9+
"Resource": "{artifactObjectsArn}"
10+
},
11+
{
12+
"Sid": "Get:BootstrapScripts",
13+
"Effect": "Allow",
14+
"Principal": {
15+
"AWS": "{accountArns}"
16+
},
17+
"Action": [
18+
"s3:GetObject"
19+
],
20+
"Resource": "{bootstrapObjectsArn}"
21+
},
22+
{
23+
"Sid": "List:BootstrapScripts",
24+
"Effect": "Allow",
25+
"Principal": {
26+
"AWS": "{accountArns}"
27+
},
28+
"Action": [
29+
"s3:ListBucket"
30+
],
31+
"Resource": "{artifactBucketArn}",
32+
"Condition": {
33+
"StringLike": {
34+
"s3:prefix": "{bootstrapPrefix}"
35+
}
36+
}
37+
},
38+
{
39+
"Sid": "Deny requests that do not use TLS",
40+
"Effect": "Deny",
41+
"Principal": "*",
42+
"Action": "s3:*",
43+
"Resource": "{artifactObjectsArn}",
44+
"Condition": {
45+
"Bool": {
46+
"aws:SecureTransport": false
47+
}
48+
}
49+
},
50+
{
51+
"Sid": "Deny requests that do not use SigV4",
52+
"Effect": "Deny",
53+
"Principal": "*",
54+
"Action": "s3:*",
55+
"Resource": "{artifactObjectsArn}",
56+
"Condition": {
57+
"StringNotEquals": {
58+
"s3:signatureversion": "AWS4-HMAC-SHA256"
59+
}
60+
}
61+
}
62+
]

0 commit comments

Comments
 (0)