This is the 15th day article of Advent Calender on the 2019 code-server.
Continuing from the last time, I would like to launch EC2 Instance.
table of contents Local environment 1st day Online environment version 1st day Improve work environment
Online environment, day 2 Create a virtual network
Online environment 3rd day Launch an EC2 instance with Boto3
Online environment 4th day Try running Code-Server in the cloud
Online environment 5th day Launch code-server on Docker
Online environment, day 6 Let's automate
Online environment 7th day Deploy compute on git on EC2
... Online version .. Built with Coompose file
Online .. Try K8S
...
Demon remodeling
Up to the last time, we have launched EC2 Instance with boto3 x python. This time, let's install Code-Server on this launched Instance.
Let's operate the created EC Instance from cli
You will need the Public IP information to make an ssh connection. You can get it with the following code.
def get_inst(ec2_client:ec2.Client, project_name="advent-code-server"):
try:
print(">>>> ec2client.describe_instances")
res = ec2_client.describe_instances(Filters=[{"Name":"tag:Name","Values":[project_name]}])
print("{}".format(res))
for reserve_info in res['Reservations']:
print("-")
for instance_info in reserve_info['Instances']:
print(">>>> {}".format(instance_info.get('InstanceId',"")))
print(">>>> {}".format(instance_info.get('PublicDnsName',"")))
print(">>>> {}".format(instance_info.get('PublicIpAddress',"")))
print(">>>> {}".format(instance_info.get('PrivateDnsName',"")))
print(">>>> {}".format(instance_info.get('PrivateIpAddress',"")))
print(">>>> {}".format(instance_info.get('State',"")))
except ClientError as e:
print("-- {}".format(e.response))
Change the security of pem files
$ chmod 600 advent-code-server.pem
Connect to ec instance with ssh
$ ssh -i advent-code-server.pem [email protected]
root@dabe0caa28a0:/works/app# ssh -i advent-code-server.pem [email protected]
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-1051-aws x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Sat Dec 21 15:32:31 UTC 2019
System load: 0.01 Processes: 88
Usage of /: 13.6% of 7.69GB Users logged in: 0
Memory usage: 14% IP address for eth0: 10.1.0.227
Swap usage: 0%
0 packages can be updated.
0 updates are security updates.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
ubuntu@ip-10-1-0-227:~$
I was able to connect !!
Start static server
ubuntu@ip-10-1-0-227:~$ sudo apt-get install python3
ubuntu@ip-10-1-0-227:~$ python3 -m http.server 8080
Let's access it with a browser at http://18.182.61.231:8080/
!!
Seems to be working fine
ubuntu@ip-10-1-0-227:~$ wget https://github.com/cdr/code-server/releases/download/2.1692-vsc1.39.2/code-server2.1692-vsc1.39.2-linux-x86_64.tar.gz
ubuntu@ip-10-1-0-227:~$ tar -xzf code-server2.1692-vsc1.39.2-linux-x86_64.tar.gz -C ./ --strip-components 1
ubuntu@ip-10-1-0-227:~$ ./code-server --cert --port 8443 ./
on https://localhost:8443
info - Password is 50cdee5af7ee7824126382ff
info - To use your own password, set the PASSWORD environment variable
info - To disable use `--auth none`
info - Using generated certificate and key for HTTPS
Let's connect to https://18.182.61.231:8443/
I was able to start it safely !!
In this state, if the SSH connection is lost, the application will end, so
ubuntu@ip-10-1-0-227:~$ ./code-server --cert --port 8443 ./&
Let's start it like this
Verification
buntu@ip-10-1-0-227:~$ jobs
[1]+ Running ./code-server --cert --port 8443 ./ &
When you want to finish
ubuntu@ip-10-1-0-227:~$ ps -aux | grep code-server
ubuntu 1786 0.2 5.2 840588 52580 ? Sl 15:48 0:00 /home/ubuntu/code-server --cert --port 8443 ./
ubuntu 1918 0.0 0.0 14856 1004 pts/1 S+ 15:51 0:00 grep --color=auto code-server
ubuntu@ip-10-1-0-227:~$ kill -9 1786
Let's install Docker and launch the image created in the local version online
https://github.com/kyorohiro/advent-2019-code-server/tree/master/remote_cs03
Recommended Posts