code-server online environment (4) Launch code-server on the EC2 instance

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

Introduction

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.

Try connecting with SSH

Let's operate the created EC Instance from cli

Get Instance information

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))

ssh connect

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 !!

Check if PORT is open! !!

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/ !!

Screen Shot 2019-12-22 at 0.36.17.png

Seems to be working fine

Let's install Code-Server !!

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 

Let's run Code-Server !!

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/

Screen Shot 2019-12-22 at 0.45.22.png Screen Shot 2019-12-22 at 0.46.07.png Screen Shot 2019-12-22 at 0.46.39.png

I was able to start it safely !!

Supplement

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

next time

Let's install Docker and launch the image created in the local version online

code

https://github.com/kyorohiro/advent-2019-code-server/tree/master/remote_cs03

Recommended Posts

code-server online environment (4) Launch code-server on the EC2 instance
code-server online environment (5) Launch code-server on Docker
code-server online environment (3) Launch an EC2 instance with Boto3
code-server online environment (7) Deploy compute on git on EC2
code-server online environment (1)
Prepare the environment of Chainer on EC2 spot instance with AWS Lambda
Launch code-server on alpine-linux
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Deployment procedure on AWS (2) Server (EC2 instance) environment settings
code-server online environment (6) Let's automate
xgboost (python) on EC2 Spot instance environment prepared by AWS Lambda
# 3 Build a Python (Django) environment on AWS EC2 instance (ubuntu18.04) part2
Create an AWS Cloud9 development environment on your Amazon EC2 instance
Set the environment variable PYTHONPATH on zsh
AWS EC2 instance launch and ssh connection
Execution environment on the Web by "Project Jupyter"
Build python environment with pyenv on EC2 (ubuntu)
Launch and use IPython notebook on the network
code-server Online environment (2) Create a virtual network with Boto3