Preparation

Last updated: 2020-10-28 11:15:00

    Before installing Tencent Cloud's command line tool TCCLI, ensure that a Python environment has been installed. For more information, see Prerequisites.

    Step 1. Installing TCCLI

    Installing TCCLI

    Run commands based on the actual situation.

    • TCCLI not installed
      Run the following command to install TCCLI through pip. For more information, see Installing TCCLI.
      $ sudo pip install tccli
    • TCCLI installed
      Run the following command to quickly upgrade TCCLI through pip:
      $ sudo pip install --upgrade tccli

    Verifying Installation

    Run the following command to check whether TCCLI is successfully installed and has Batch-related capabilities:

    tccli batch help

    The returned result is as follows, indicating that TCCLI is successfully installed:

    NAME
            batch
    DESCRIPTION
            batch-2017-03-12
    USEAGE
            tccli batch <action> [--param...]
    OPTIONS
            help
            show the tccli batch help info
            --version
            specify a batch api version
    AVAILABLE ACTION
            DescribeComputeEnv
            Used to query details of the computing environment
            CreateTaskTemplate
            Used to create a task template

    Step 2. Configuring TCCLI

    1. Log in to the API Key Management.
    2. Click Create Key or use an available key to record SecretID and SecretKey. See the figure below:
    3. Run the tccli configure command and enter the TCCLI configuration information. For more information, see Configuring TCCLI.
      $ tccli configure
      TencentCloud API secretId[None]:
      TencentCloud API secretKey[None]:
      region[None]:
      output[json]:

    Step 3. Preparing the COS Directory

    Creating a Bucket and Subfolders

    1. Log in to the COS console and choose Bucket List in the left sidebar.
    2. Create a bucket and create 3 folders in the bucket. See the figure below:

    Acquiring COS

    1. Click Basic Configuration on the left to view the endpoint in Basic Information. See the figure below:
    2. Acquire the endpoints of subfolders in the a COS bucket.

      Acquire COS-related endpoints based on the actual situation.

      The acquired COS bucket endpoint is https://batchdemo-xxxxxxxxx.cos.ap-guangzhou.myqcloud.com. The endpoints of the three folders created in Creating a Bucket and Subfolders can be acquired by combining domain and subfolder names as follows:
      • cos://batchdemo-xxxxxxxxx.cos.ap-guangzhou.myqcloud.com/logs/
      • cos://batchdemo-xxxxxxxxx.cos.ap-guangzhou.myqcloud.com/input/
      • cos://batchdemo-xxxxxxxxx.cos.ap-guangzhou.myqcloud.com/output/

    Step 4. Downloading the Demo File

    Access the Batch demo, download the test package, and decompress it.

    The demo is provided in the format of the Python+Batch command line tool. Since Batch has many capabilities and configuration items, you can work with it more conveniently by using Python scripts.

    Step 5. Modifying Demo Custom Information

    Change the general part of the custom information about the Batch demo. Modify all files in Demo as follows:

    Use the following custom information in 1_SimpleStart.py as an example:

    # custom (Change to your info)
    imageId = "img-m4q71qnf"
    Application = {
        "DeliveryForm": "LOCAL",
        "Command": " python -c \"fib=lambda n:1 if n<=2 else fib(n-1)+fib(n-2); print(fib(20))\" "
    }
    StdoutRedirectPath = "cos://batchdemo-xxxxxxxxxx.cos.ap-guangzhou.myqcloud.com/logs/"
    StderrRedirectPath = "cos://batchdemo-xxxxxxxxxx.cos.ap-guangzhou.myqcloud.com/logs/"

    The following table lists the information to be modified.

    Configuration Item Description
    imageId
    • The image containing the Cloud-init service is required.
    • Custom images are created based on this image.
    StdoutRedirectPath Enter the complete log folder endpoint acquired in Acquiring COS-related endpoints.
    StderrRedirectPath
    Application The startup command. Use the default setting.
    cmd = "tccli batch SubmitJob \
        --version 2017-03-12 \
        --Placement '{\"Zone\": \"ap-guangzhou-2\"}' \
        --Job ' %s ' "%(json.dumps(testJob))

    The demo specifies Guangzhou Zone 2 for resource application. You can select the corresponding availability zone to apply for resources based on the default region configured in TCCLI.
    For more information about regions and availability zones, see Regions and Availability Zones.

    Step 6 Performing a Test

    Experience the Batch usage methods and computing capability in the following sequence according to the reference course.

    1. 1_SimpleStart.py: Quick Start
    2. 2_RemoteCodePkg.py: Running Remote Package
    3. 3_StoreMapping.py: Mapping Remote Storage