Install AppServer and make your first API call to ApsaraVideo VOD.
To call the APIs for ApsaraVideo VOD entities and playlists, you must submit a ticket to add your account to the allowlist.
Quick walkthrough
-
Clone the project.
git clone https://github.com/MediaBox-Demos/VodAppServer.git cd VodAppServer -
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.
-
-
Start the service.
mvn spring-boot:runThe 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 -
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.
-
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. -
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 -
Create a function.
-
Go to the Functions page of the Function Compute (FC) console and click Create Function.
-
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, andALIYUN_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.
-
-
Click Create.
-
-
Create a trigger.
-
On the Function Details page, click the Triggers tab.
-
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.
-
Click OK.
-
-
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:
-
Verify that the directory structure of the
VodAppServer.zippackage is correct. -
Verify that the startup command configured for the function is correct.
-
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.