Skip to content

Commit 806c393

Browse files
committed
[Infrastructure] Add 1-click template to deploy environment for PCUI private deployment.
1 parent 0926bc6 commit 806c393

File tree

1 file changed

+206
-0
lines changed

1 file changed

+206
-0
lines changed
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
AWSTemplateFormatVersion: 2010-09-09
2+
Description: AWS ParallelCluster UI - Resources for Private Deployment
3+
4+
Parameters:
5+
Vpc:
6+
Description: VPC ID to create the VPC Endpoint in.
7+
Type: AWS::EC2::VPC::Id
8+
PrivateSubnetOne:
9+
Description: Subnet ID of the first private subnet that will be used by the PCUI lambda.
10+
Type: AWS::EC2::Subnet::Id
11+
PrivateSubnetTwo:
12+
Description: Subnet ID of the seconds private subnet that will be used by the PCUI lambda.
13+
Type: AWS::EC2::Subnet::Id
14+
PrivateSubnetThree:
15+
Description: Subnet ID of the seconds private subnet that will be used by the PCUI lambda.
16+
Type: AWS::EC2::Subnet::Id
17+
DcvInstanceAmiId:
18+
Description: |
19+
AMI for the DCV node. Must be a DCV AMI, e.g. DCV-AmazonLinux2-x86_64-*.
20+
DCV AMI can be retrieved with the command:
21+
aws ec2 describe-images
22+
--filters "Name=owner-alias,Values=amazon" "Name=name,Values=DCV-AmazonLinux2-x86_64-*" "Name=creation-date,Values=2024-10-*" "Name=architecture,Values=x86_64" "Name=is-public,Values=true"
23+
--query 'Images[].{Name:Name,ImageId:ImageId}'
24+
--output table
25+
Type: String
26+
DcvInstanceKeypair:
27+
Description: EC2 Keypair for the client node.
28+
Type: AWS::EC2::KeyPair::KeyName
29+
DcvInstanceType:
30+
Description: Instance type for the DCV instance. Must have a NVIDIA GPU.
31+
Type: String
32+
Default: g4dn.xlarge
33+
DcvInstancePublicSubnet:
34+
Description: Subnet ID of the public subnet where the client instance will run.
35+
Type: AWS::EC2::Subnet::Id
36+
DcvSessionUser:
37+
Description: Username for the DCV session.
38+
Type: String
39+
Default: ec2-user
40+
MinLength: 3
41+
MaxLength: 64
42+
DcvSessionPassword:
43+
Description: Password for the DCV session.
44+
Type: String
45+
Default: password
46+
MinLength: 3
47+
MaxLength: 64
48+
NoEcho: true
49+
AllowedDcvSourcePrefixList:
50+
Description: Allowed prefix list for DCV traffic source.
51+
Type: String
52+
53+
Metadata:
54+
AWS::CloudFormation::Interface:
55+
ParameterGroups:
56+
- Label:
57+
default: Networking
58+
Parameters:
59+
- Vpc
60+
- PrivateSubnetOne
61+
- PrivateSubnetTwo
62+
- PrivateSubnetThree
63+
- Label:
64+
default: DCV Instance
65+
Parameters:
66+
- DcvInstanceAmiId
67+
- DcvInstanceType
68+
- DcvInstanceKeypair
69+
- DcvInstancePublicSubnet
70+
- Label:
71+
default: DCV Session
72+
Parameters:
73+
- DcvSessionUser
74+
- DcvSessionPassword
75+
76+
Mappings:
77+
Dcv:
78+
Constants:
79+
Port: 8443
80+
81+
Resources:
82+
VpcEndpoint:
83+
Type: AWS::EC2::VPCEndpoint
84+
Properties:
85+
SecurityGroupIds:
86+
- !Ref VpcEndpointSecurityGroup
87+
ServiceName: !Sub "com.amazonaws.${AWS::Region}.execute-api"
88+
SubnetIds:
89+
- !Ref PrivateSubnetOne
90+
- !Ref PrivateSubnetTwo
91+
- !Ref PrivateSubnetThree
92+
VpcEndpointType: Interface
93+
VpcId: !Ref Vpc
94+
95+
VpcEndpointSecurityGroup:
96+
Type: AWS::EC2::SecurityGroup
97+
Properties:
98+
GroupDescription: Security Group for the VPC Endpoint.
99+
VpcId: !Ref Vpc
100+
101+
DcvSecurityGroup:
102+
Type: AWS::EC2::SecurityGroup
103+
Properties:
104+
GroupDescription: Security Group for the DCV instance.
105+
VpcId: !Ref Vpc
106+
107+
PCUILambdaSecurityGroup:
108+
Type: AWS::EC2::SecurityGroup
109+
Properties:
110+
GroupDescription: Security Group for the PCUI Lambda.
111+
VpcId: !Ref Vpc
112+
113+
DcvSecurityGroupIngressFromPrefixList:
114+
Type: AWS::EC2::SecurityGroupIngress
115+
Properties:
116+
Description: Allow DCV traffic from the prefix list.
117+
GroupId: !Ref DcvSecurityGroup
118+
SourcePrefixListId: !Ref AllowedDcvSourcePrefixList
119+
IpProtocol: TCP
120+
FromPort: !FindInMap [ Dcv, Constants, Port ]
121+
ToPort: !FindInMap [ Dcv, Constants, Port ]
122+
123+
VpcEndpointSecurityGroupIngressFromDcv:
124+
Type: AWS::EC2::SecurityGroupIngress
125+
Properties:
126+
Description: Allow HTTPS traffic from the DCV Security Group.
127+
GroupId: !Ref VpcEndpointSecurityGroup
128+
SourceSecurityGroupId: !Ref DcvSecurityGroup
129+
IpProtocol: TCP
130+
FromPort: 443
131+
ToPort: 443
132+
133+
VpcEndpointSecurityGroupIngressFromPCUILambda:
134+
Type: AWS::EC2::SecurityGroupIngress
135+
Properties:
136+
Description: Allow HTTPS traffic from the PCUI Lambda Security Group.
137+
GroupId: !Ref VpcEndpointSecurityGroup
138+
SourceSecurityGroupId: !Ref PCUILambdaSecurityGroup
139+
IpProtocol: TCP
140+
FromPort: 443
141+
ToPort: 443
142+
143+
DcvInstance:
144+
Type: AWS::EC2::Instance
145+
CreationPolicy:
146+
ResourceSignal:
147+
Timeout: PT10M
148+
Properties:
149+
ImageId: !Ref DcvInstanceAmiId
150+
InstanceType: !Ref DcvInstanceType
151+
KeyName: !Ref DcvInstanceKeypair
152+
SecurityGroupIds:
153+
- Ref: DcvSecurityGroup
154+
SubnetId: !Ref DcvInstancePublicSubnet
155+
Tags:
156+
- Key: Name
157+
Value: PCUI-DcvInstance
158+
UserData:
159+
Fn::Base64:
160+
!Sub
161+
- |
162+
#!/bin/bash -e
163+
164+
# Create DCV session for ec2-user
165+
# Ref: https://www.ni-sp.com/support/how-to-install-nice-dcv-on-aws-ec2/
166+
echo "${DcvSessionPassword}" | sudo passwd ${DcvSessionUser} --stdin
167+
sudo -u ${DcvSessionUser} dcv create-session session1
168+
169+
# Install Chromium Browser
170+
# Ref: https://stackoverflow.com/questions/72077341/how-do-you-install-chrome-on-amazon-linux-2
171+
sudo amazon-linux-extras install epel -y
172+
sudo yum install -y chromium
173+
174+
/opt/aws/bin/cfn-signal -e "$?" --stack "${AWS::StackName}" --resource DcvInstance --region "${AWS::Region}"
175+
176+
- DcvSessionUser: !Ref DcvSessionUser
177+
DcvSessionPassword: !Ref DcvSessionPassword
178+
179+
Outputs:
180+
VpcEndpoint:
181+
Value: !Ref VpcEndpoint
182+
Description: The VPC Endpoint.
183+
VpcEndpointSecurityGroup:
184+
Value: !Ref VpcEndpointSecurityGroup
185+
Description: The Security Group attached to the VPC Endpoint.
186+
VpcEndpointSubnetOne:
187+
Value: !Ref PrivateSubnetOne
188+
Description: The first subnet of the VPc Endpoint.
189+
VpcEndpointSubnetTwo:
190+
Value: !Ref PrivateSubnetTwo
191+
Description: The second subnet of the VPc Endpoint.
192+
VpcEndpointSubnetThree:
193+
Value: !Ref PrivateSubnetThree
194+
Description: The third subnet of the VPc Endpoint.
195+
PCUILambdaSecurityGroup:
196+
Value: !Ref PCUILambdaSecurityGroup
197+
Description: The security group for PCUI Lambda.
198+
DcvInstance:
199+
Value: !Ref DcvInstance
200+
Description: The EC2 instance running DCV server.
201+
DcvInstanceIp:
202+
Value: !GetAtt DcvInstance.PublicIp
203+
Description: The public IP of the DCV instance.
204+
DcvInstancePort:
205+
Value: !FindInMap [ Dcv, Constants, Port ]
206+
Description: The port to connect to the DCV instance.

0 commit comments

Comments
 (0)