code-server online environment (1)

This is the 12th day article of Advent Calender on the 2019 code-server. In What is code-server? on the first day, VSCode is built in using Docker and Docker-Compose in the local environment. I created a development environment. Starting today, we will enter the online version. In the online version, we will launch an Instance on the cloud and place Code-Server there. This gives you access to your development resources from anywhere. Very expensive machine You can use it for a short period of time You will be able to write programs even when you are out using an iPad.

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

Let's launch EC2 Instance

I was wondering which environment to use, but decided to use AWS for orthodox. AWS has a service that uses Docker. You can use the Compose file learned in the local version as it is for release. You can use the current method using K8S. But this time, I'd like to start by launching EC2 Instace.

Use Boto3

There are several ways to launch an Instance on AWS. --Leadingly operating the GUI console --Use configuration management tools such as CloudFormation and Terraform --Do it from the command line using the AWS CLI --Programmatically using the AWS SDK

I think the standard is to use a configuration management tool. I would like to write in Boto3.

Get the ACCESS KEY.

In order to use it from the SDK, you need to get the ACCESS KEY ID and SECRET KEY.

https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-chap-configure.html

As described in

1.Sign in to the AWS Management Console and go to the IAM Console (https)://console.aws.amazon.com/iam/) Is opened.

2.In the navigation pane[Users]Choose.

3.Select the user name for which you want to create an access key[Security credentials]Select a tab.

4. [Access keys (access key)]In the section[Create access key (access keyの作成)]Choose.

5.To view the new access key pair[Show]Choose. After closing this dialog box, you will not be able to access the secret access key again. The authentication information is as follows.

Access key ID: AKIAIOSFODNN7EXAMPLE

Secret access key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

Prepare a development environment operated by AWS.

You can use the Docker created so far as it is.

FROM python:3.8.0-buster

RUN apt-get update
# code-Install wget to get the server
RUN apt-get install -y wget

#Working directory/Make it works. Anywhere is fine
WORKDIR /works

# code-Get the server binary
RUN 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

# code-server/Unzip under works
RUN tar -xzf code-server2.1692-vsc1.39.2-linux-x86_64.tar.gz -C ./ --strip-components 1 

WORKDIR /works/app
ENV PYTHONPATH=/works/app

#Install python plugin
RUN /works/code-server --install-extension ms-python.python
RUN /usr/local/bin/python -m pip install -U pylint --user
RUN apt-get install groff -y

#The default is/works/Make it start with app.
CMD [ "/works/code-server", "--allow-http", "--auth", "none", "--port", "8443", "/works/app"]

It's the same !! The environment including docker-compose is set below.

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

requirements.txt changes

awscli==1.16.300
boto3==1.10.36
botocore==1.13.36
boto3-type-annotations==0.3.1
rope==0.14.0

Let's launch

$ docker-compose build
$ docker-compose up -d

Let's open VSCode

Try opening http://127.0.0.1:8443/ in your browser.

Screen Shot 2019-12-17 at 0.28.58.png

Let's set ACCESS KEY ID and SECRET KEY

Open VSCode terminal and install aws cli

$ pip install -r requirements.txt 

Set up AWS commands. Add the ACCESS KEY ID and SECRET KEY. If you want to use TOKYO for the region, specify ʻap-northeast-1`.

$ aws configure
AWS Access Key ID [None]: xxxx
AWS Secret Access Key [None]: xxxxx
Default region name [None]: ap-northeast-1
Default output format [None]: json

Try hitting the AWS CLI command

$ aws ec2 describe-instances

next time

Let's create / delete Instance using Boto3.

code

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

Recommended Posts

code-server online environment (1)
code-server online environment (6) Let's automate
code-server online environment (5) Launch code-server on Docker
code-server online environment (4) Launch code-server on the EC2 instance
code-server online environment (7) Deploy compute on git on EC2
code-server Online environment (2) Create a virtual network with Boto3
code-server Local environment (3) Try using VSCode Plugin