Quick start

更新时间:
复制 MD 格式

Install AppServer and make your first API call to ApsaraVideo VOD.

Important

To call the APIs for ApsaraVideo VOD entities and playlists, you must submit a ticket to add your account to the allowlist.

Quick walkthrough

  1. Clone the project.

    git clone https://github.com/MediaBox-Demos/VodAppServer.git
    cd VodAppServer
  2. Configure your credentials and region.

    Add the following configuration to application.yml:

    aliyun:
      vod:
        ak: YOUR_ACCESS_KEY_ID      # Your Alibaba Cloud AccessKey ID
        sk: YOUR_ACCESS_KEY_SECRET  # Your Alibaba Cloud AccessKey Secret
        region: cn-shanghai         # The region ID. This must match the region where you enabled ApsaraVideo VOD.
    Note
    • To obtain an AccessKey pair, see Create an AccessKey.

    • The region must be the same as the one you selected in the ApsaraVideo VOD console.

  3. Start the service.

    mvn spring-boot:run

    The following log output indicates a successful start. The region in the log must match the one you configured in step 2.

    VOD client initialized successfully, Region: cn-shanghai
    Started Application in 5.234 seconds
  4. Test the API.

    # Get a list of playlists
    curl -X POST http://localhost:9000/appServer/getPlaylists \
      -H "Content-Type: application/json" \
      -d '{"pageNo":"1","pageSize":"10"}'

    This completes the quick walkthrough.

Deploy to Function Compute

Function Compute (FC) provides serverless deployment with no server maintenance and pay-as-you-go billing.

  1. Build the project.

    # Go to the project directory
    cd VodAppServer
    # Package with Maven
    mvn clean package
    # After a successful build, target/VodAppServer-1.0-SNAPSHOT.jar is generated.
  2. Prepare the deployment package.

    # Create the directory structure for deployment
    mkdir -p deploy/VodAppServer/target
    # Copy the JAR file
    cp target/VodAppServer-1.0-SNAPSHOT.jar deploy/VodAppServer/target/
    # Go to the deployment directory
    cd deploy
    # Compress the directory into a ZIP file
    zip -r VodAppServer.zip VodAppServer/

    The directory structure is as follows:

    VodAppServer.zip
    └── VodAppServer/
        └── target/
            └── VodAppServer-1.0-SNAPSHOT.jar
  3. Create a function.

    1. Go to the Functions page of the Function Compute (FC) console and click Create Function.

    2. Select Web Function and configure the following parameters:

      • Memory: 1024 MB.

      • Runtime: Custom Runtime > Java > Java 8.

      • Code Upload Method: Upload a .zip file.

      • Code Package: Upload the VodAppServer.zip deployment package from the previous step.

      • Startup Command: java -jar /code/VodAppServer/target/VodAppServer-1.0-SNAPSHOT.jar.

      • Environment Variables: In the Advanced Settings > More Configurations section, add ACCESS_KEY_ID, ACCESS_KEY_SECRET, and ALIYUN_VOD_REGION. These correspond to your AccessKey ID, AccessKey Secret, and region.

      • Leave other parameters at their default values and click Create to deploy the function.

    3. Click Create.

  4. Create a trigger.

    1. On the Function Details page, click the Triggers tab.

    2. Click Create Trigger and select HTTP Trigger. For Authentication Method, choose No Authentication. Configure the HTTP Trigger with the following settings: select LATEST for version or alias; allow GET, POST, PUT, and DELETE request methods; and select No Authentication as the authentication method.

    3. Click OK.

  5. Test the deployment.

    Use the public URL to verify the deployment:

    # Replace this with your actual URL
    curl -X POST https://vod-app-function-xxx.cn-shanghai.fcapp.run/appServer/getPlaylists \
      -H "Content-Type: application/json" \
      -d '{"pageNo":"1","pageSize":"10"}'

FAQ

Function start failure

Check the following:

  1. Verify that the directory structure of the VodAppServer.zip package is correct.

  2. Verify that the startup command configured for the function is correct.

  3. Verify that the JAR file from the project build is complete and not corrupted.

Environment variables not taking effect

Verify that the environment variable names are correct, then restart the function. Use System.getenv() in your project to retrieve them.

Update deployment code

Repackage and upload a new VodAppServer.zip package. The function restarts automatically.