Updated on 2025-08-07 GMT+08:00

Purchasing an ECS

  1. Log in to the ECS console.
  2. In the navigation pane on the left, choose Elastic Cloud Server. In the upper right corner, click Buy ECS. For details, see Buying an ECS. Select the VPC, subnet, and security group created in Creating a VPC, Subnet, and Security Group.
  3. Return to the ECS list and click Remote Login in the Operation column.

    Figure 1 Remote login

  4. In the displayed dialog box, click Log In and enter the password to access the CloudShell terminal console.

    Ensure that the security group allows access from the port (22 by default) used for CloudShell logins.

  5. In the usr directory, run the mkdir and openssl commands to create the local/test directory and generate the key certificate in the test directory.

    1. Run the following command to create the local/test directory in the usr directory:
      mkdir -p local/test
    2. Run the following command to go to the test directory and generate the key certificate:
      openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365
    3. After the command in step 2 is executed, set PEM PASS to privatenetwork. After the setting is complete, enter the related information as prompted.
      Figure 2 Generating the key certificate

  6. In the test directory, use Python 3 to set up a Python server.

    Run the following command to create a python file in the test directory:
    vi  httpsserver.py

    Enter the following content into the python file:

    from http.server import HTTPServer, BaseHTTPRequestHandler
    
    from io import BytesIO
    import ssl
    
    
    class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
    
        def do_GET(self):
            self.send_response(200)
            self.end_headers()
            self.wfile.write(b'Hello, world!')
    
        def do_POST(self):
            content_length = int(self.headers['Content-Length'])
            body = self.rfile.read(content_length)
            self.send_response(200)
            self.end_headers()
            response = BytesIO()
            response.write(b'This is POST request. ')
            response.write(b'Received: ')
            response.write(body)
            print(body)
            self.wfile.write(response.getvalue())
    
    
    httpd = HTTPServer(('0.0.0.0', 8000), SimpleHTTPRequestHandler)
    httpd.socket = ssl.wrap_socket (httpd.socket,
            keyfile="key.pem",
            certfile='cert.pem', server_side=True)
    httpd.serve_forever()

  7. Install Python 3 and configure environment variables. Run the following command to start the httpsserver.

    python3 httpsserver.py