-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtemplate-unicast.yml
455 lines (444 loc) · 17.5 KB
/
template-unicast.yml
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
AWSTemplateFormatVersion: 2010-09-09
Description: CARLA Simulator Ubuntu with NICE DCV (login as ubuntu)
Metadata:
License:
Description: |
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.
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Instance type
Parameters:
- ImageId
- instanceType
- Label:
default: EC2 configuration
Parameters:
- ec2Name
- Label:
default: EBS volume configuration
Parameters:
- volumeSize
- volumeType
- Label:
default: Biga configuration
Parameters:
- BigaAmiId
- BigaInstanceType
Parameters:
instanceType:
Type: String
Description: Accelerated Instance Type ( https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/accelerated-computing-instances.html )
AllowedValues:
- g4dn.xlarge
- g4dn.2xlarge
- g4dn.4xlarge
- g4dn.8xlarge
- g4dn.12xlarge
- g4dn.16xlarge
- g5.xlarge
- g5.2xlarge
- g5.4xlarge
- g5.8xlarge
- g5.12xlarge
- g5.16xlarge
ConstraintDescription: Must contain valid instance type.
Default: g5.16xlarge
ec2Name:
Description: EC2 instance name
Type: String
Default: Ubuntu-CARLA-NICE-DCV
volumeType:
Type: String
Description: Volume Type ( https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volume-types.html )
AllowedValues:
- gp2
- gp3
Default: gp3
volumeSize:
Type: Number
Description: Volume Size in GiBs (must be equal or larger than snapshot size)
Default: 40
ImageId:
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Description: Ubuntu 20.04 (x86_64)
Default: /aws/service/canonical/ubuntu/server/20.04/stable/current/amd64/hvm/ebs-gp2/ami-id
BigaAmiId:
Type: AWS::EC2::Image::Id
Description: The Biga ami image id
BigaInstanceType:
Type: String
Description: Instance type for the biga image
Default: t4g.micro
BigaInstanceName:
Type: String
Description: Name of Biga Instance
Default: Biga
Resources:
vpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsSupport: true
PrivateSubnet:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.1.0/24
AvailabilityZone: !Select [0, !GetAZs '']
VpcId: !Ref vpc
PublicSubnet:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.2.0/24
AvailabilityZone: !Select [0, !GetAZs '']
VpcId: !Ref vpc
MapPublicIpOnLaunch: true
InternetGateway:
Type: AWS::EC2::InternetGateway
InternetGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref vpc
InternetGatewayId: !Ref InternetGateway
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref vpc
PublicRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet
NatIP:
Type: AWS::EC2::EIP
DependsOn: vpc
Properties:
Domain: vpc
NatGateway:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt NatIP.AllocationId
SubnetId: !Ref PublicSubnet
PrivateRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref vpc
PrivateRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateRouteTable
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway
PrivateSubnetRouteTableAssocation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PrivateSubnet
RouteTableId: !Ref PrivateRouteTable
BigaSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow Traffic From Carla
VpcId: !Ref vpc
SecurityGroupIngress:
- IpProtocol: tcp
Description: SSH
FromPort: "22"
ToPort: "22"
CidrIp: 10.0.0.0/16
- IpProtocol: udp
Description: Ingress traffic (UDP) for ROS2
FromPort: '7400'
ToPort: '65400'
CidrIp: 10.0.0.0/16
- IpProtocol: udp
Description: vCAN
FromPort: '3030'
ToPort: '3030'
CidrIp: 10.0.0.0/16
Tags:
- Key: StackName
Value: !Sub ${AWS::StackName}
- Key: StackId
Value: !Sub ${AWS::StackId}
- Key: Name
Value: !Sub "[${AWS::StackName}] - ${ec2Name}"
instanceIamRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: dcvLicensing
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:GetObject
Resource: !Sub arn:${AWS::Partition}:s3:::dcv-license.${AWS::Region}/*
ManagedPolicyArns:
- !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonSSMManagedInstanceCore
Tags:
- Key: StackName
Value: !Sub ${AWS::StackName}
- Key: StackId
Value: !Sub ${AWS::StackId}
instanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: /
Roles:
- !Ref instanceIamRole
Ec2InstanceCarlaNetworkInterface:
Type: AWS::EC2::NetworkInterface
Properties:
SubnetId: !Ref PrivateSubnet
Description: "Network interface for ec2InstanceCarla"
GroupSet:
- !Ref BigaSecurityGroup
ec2InstanceCarla:
Type: AWS::EC2::Instance
CreationPolicy:
ResourceSignal:
Timeout: PT90M
Metadata:
Comment: Install Desktop Environment
AWS::CloudFormation::Init:
configSets:
setup:
- 00_setup
00_setup:
files:
/home/ubuntu/update-dcv:
content: |
#!/bin/bash
cd /tmp
if ((uname -a | grep x86 1>/dev/null) && (cat /etc/os-release | grep 22.04 1>/dev/null)); then
rm -f /tmp/nice-dcv-ubuntu1804-x86_64.tgz
wget https://d1uj6qtbmh3dt5.cloudfront.net/nice-dcv-ubuntu2204-x86_64.tgz
tar -xvzf nice-dcv-ubuntu*.tgz && cd nice-dcv-*-x86_64
elif ((uname -a | grep x86 1>/dev/null) && (cat /etc/os-release | grep 18.04 1>/dev/null)); then
rm -f /tmp/nice-dcv-ubuntu1804-x86_64.tgz
wget https://d1uj6qtbmh3dt5.cloudfront.net/nice-dcv-ubuntu1804-x86_64.tgz
tar -xvzf nice-dcv-ubuntu*.tgz && cd nice-dcv-*-x86_64
elif (cat /etc/os-release | grep 18.04 1>/dev/null); then
rm -f /tmp/nice-dcv-ubuntu1804-aarch64.tgz
wget https://d1uj6qtbmh3dt5.cloudfront.net/nice-dcv-ubuntu1804-aarch64.tgz
tar -xvzf nice-dcv-ubuntu*.tgz && cd nice-dcv-*-aarch64
else
rm -f /tmp/nice-dcv-ubuntu2004-x86_64.tgz
wget https://d1uj6qtbmh3dt5.cloudfront.net/nice-dcv-ubuntu2004-x86_64.tgz
tar -xvzf nice-dcv-ubuntu*.tgz && cd nice-dcv-*-x86_64
fi
sudo apt-get install -y ./nice-dcv-server_*.deb
sudo apt-get install -y ./nice-dcv-web-viewer_*.deb
sudo apt-get install -y ./nice-xdcv_*.deb
mode: "000755"
owner: ubuntu
group: users
/home/ubuntu/update-awscli:
content: |
#!/bin/bash
cd /tmp
rm -f /tmp/awscliv2.zip
if (uname -a | grep x86 1>/dev/null); then
curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip
else
curl https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip -o awscliv2.zip
fi
unzip -q -o awscliv2.zip
sudo ./aws/install --update -b /usr/bin
mode: "000755"
owner: ubuntu
group: users
/home/ubuntu/install-carla:
content: |
#!/bin/bash
# install Python3.8 as default
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt-get update
sudo apt-get -q -y install python3.8 python3.8-dev python3.8-venv python3.8-distutils
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1AF1527DE64CB8D9
sudo add-apt-repository -y "deb [arch=amd64] http://dist.carla.org/carla focal main"
sudo apt-get update
sudo apt-get -y install libomp5 carla-simulator
python -m ensurepip --upgrade
python -m venv ~/venv
source ~/venv/bin/activate
python -m pip install --upgrade pip
python -m pip install carla==0.9.13
python -m pip install -r /opt/carla-simulator/PythonAPI/examples/requirements.txt
mode: "000755"
owner: ubuntu
group: users
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref instanceType
IamInstanceProfile: !Ref instanceProfile
Monitoring: true
NetworkInterfaces:
- NetworkInterfaceId: !Ref Ec2InstanceCarlaNetworkInterface
DeviceIndex: "0"
BlockDeviceMappings:
- DeviceName: /dev/sda1
Ebs:
VolumeType: !Ref volumeType
VolumeSize: !Ref volumeSize
DeleteOnTermination: true
UserData: !Base64
Fn::Sub: |
#!/bin/bash
cd /root/
# https://stackoverflow.com/questions/33370297/apt-get-update-non-interactive
export DEBIAN_FRONTEND=noninteractive
apt-get update
# https://docs.aws.amazon.com/systems-manager/latest/userguide/agent-install-ubuntu.html#agent-install-ubuntu-tabs
apt-get install -q -y python-setuptools wget tmux unzip tar curl sed
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/releasehistory-aws-cfn-bootstrap.html#releasehistory-aws-cfn-bootstrap-v1
wget -nv https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-1.4-34.tar.gz
tar -xvzf ./aws-cfn-bootstrap-1.4-34.tar.gz
cd aws-cfn-bootstrap-1.4
python2 setup.py build
python2 setup.py install
# cfn-init
python2 /usr/local/bin/cfn-init -v --stack ${AWS::StackName} --resource ec2InstanceCarla --region ${AWS::Region} -c setup
# install firefox browser
apt-get -q -y install firefox
# https://docs.aws.amazon.com/dcv/latest/adminguide/setting-up-installing-linux-prereq.html
systemctl isolate multi-user.target
apt-get -q -y install ubuntu-desktop
apt-get -q -y install gdm3
apt-get -q -y install pulseaudio-utils
# resolve "/var/lib/dpkg/info/nice-dcv-server.postinst: 8: dpkg-architecture: not found" when installing dcv-server
apt-get -q -y install dpkg-dev
sed -i "s/^#WaylandEnable=false/WaylandEnable=false/g" /etc/gdm3/custom.conf
# https://docs.aws.amazon.com/dcv/latest/adminguide/setting-up-installing-linux-server.html
wget -nv https://d1uj6qtbmh3dt5.cloudfront.net/NICE-GPG-KEY
gpg --import NICE-GPG-KEY
# https://docs.aws.amazon.com/dcv/latest/adminguide/setting-up-installing-linux-server.html#linux-server-install
if ((uname -a | grep x86 1>/dev/null) && (cat /etc/os-release | grep 22.04 1>/dev/null)); then
wget -nv https://d1uj6qtbmh3dt5.cloudfront.net/nice-dcv-ubuntu2204-x86_64.tgz
tar -xvzf nice-dcv-ubuntu*.tgz && cd nice-dcv-*-x86_64
elif ((uname -a | grep x86 1>/dev/null) && (cat /etc/os-release | grep 18.04 1>/dev/null)); then
wget -nv https://d1uj6qtbmh3dt5.cloudfront.net/nice-dcv-ubuntu1804-x86_64.tgz
tar -xvzf nice-dcv-ubuntu*.tgz && cd nice-dcv-*-x86_64
elif (cat /etc/os-release | grep 18.04 1>/dev/null); then
wget -nv https://d1uj6qtbmh3dt5.cloudfront.net/nice-dcv-ubuntu1804-aarch64.tgz
tar -xvzf nice-dcv-ubuntu*.tgz && cd nice-dcv-*-aarch64
else
wget -nv https://d1uj6qtbmh3dt5.cloudfront.net/nice-dcv-ubuntu2004-x86_64.tgz
tar -xvzf nice-dcv-ubuntu*.tgz && cd nice-dcv-*-x86_64
fi
apt-get -q -y install ./nice-dcv-server_*.deb
apt-get -q -y install ./nice-dcv-web-viewer_*.deb
usermod -aG video dcv
apt-get -q -y install ./nice-xdcv_*.deb
# https://docs.aws.amazon.com/dcv/latest/adminguide/enable-quic.html
cp /etc/dcv/dcv.conf /etc/dcv/dcv.conf.org
sed -i '/^\[connectivity/a enable-quic-frontend=true' /etc/dcv/dcv.conf
# session storage: https://docs.aws.amazon.com/dcv/latest/userguide/using-transfer.html
mkdir -p /home/ubuntu/DCV-Storage
chown -R ubuntu:ubuntu /home/ubuntu/DCV-Storage
# https://docs.aws.amazon.com/dcv/latest/adminguide/managing-sessions-start.html#managing-sessions-start-manual
cat << EoF > /etc/systemd/system/dcv-virtual-session.service
[Unit]
Description=Create DCV virtual session for user ubuntu
After=default.target network.target
[Service]
ExecStart=/opt/dcv-virtual-session.sh
[Install]
WantedBy=default.target
EoF
cat << EoF > /opt/dcv-virtual-session.sh
#!/bin/bash
dcvUser=ubuntu
while true;
do
if (/usr/bin/dcv list-sessions | grep \$dcvUser 1>/dev/null)
then
sleep 5
else
/usr/bin/dcv create-session \$dcvUser --owner \$dcvUser --storage-root /home/\$dcvUser/DCV-Storage
/usr/bin/dcv list-sessions
fi
done
EoF
chmod +x /opt/dcv-virtual-session.sh
cd /root/
apt-get -y autoremove
# https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
if (uname -a | grep x86 1>/dev/null); then
curl -s https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip
else
curl -s https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip -o awscliv2.zip
fi
unzip -q -o awscliv2.zip
./aws/install -b /usr/bin
echo "export AWS_CLI_AUTO_PROMPT=on-partial" >> /home/ubuntu/.bashrc
# text console: DCV virtual sessions only
systemctl isolate multi-user.target
systemctl set-default multi-user.target
systemctl daemon-reload
systemctl enable --now dcvserver dcv-virtual-session.service
# Nvidia Drivers
apt install -q -y $(nvidia-detector)
# cfn-init completed so signal success or not
python2 /usr/local/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource ec2InstanceCarla --region ${AWS::Region}
reboot
Tags:
- Key: Name
Value: !Ref ec2Name
- Key: StackName
Value: !Sub ${AWS::StackName}
- Key: StackId
Value: !Sub ${AWS::StackId}
Ec2InstanceBigaNetworkInterface:
Type: AWS::EC2::NetworkInterface
Properties:
SubnetId: !Ref PrivateSubnet
Description: "Network interface for ec2InstanceBiga"
GroupSet:
- !Ref BigaSecurityGroup
ec2InstanceBiga:
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref BigaAmiId
InstanceType: !Ref BigaInstanceType
NetworkInterfaces:
- NetworkInterfaceId: !Ref Ec2InstanceBigaNetworkInterface
DeviceIndex: "0"
Tags:
- Value: Name
Key: !Ref BigaInstanceName
Outputs:
InstanceID:
Description: EC2 Instance ID
Value: !Ref ec2InstanceCarla
SSMsessionManager:
Description: SSM Session Manager login ("sudo passwd ubuntu" to change password)
Value: !Sub https://${AWS::Region}.console.aws.amazon.com/systems-manager/session-manager/${ec2InstanceCarla}
DCVdownload:
Description: DCV client download
Value: https://download.nice-dcv.com
CARLAinstall:
Description: Command to download and install CARLA
Value: /home/ubuntu/install-carla
CARLApath:
Description: CARLA installation target path
Value: /opt/carla-simulator/