Develop a custom application develop
Before you begin to develop a custom application:
- Ensure that all the prerequisites are met.
- Install the required software tools.
- See set up your environment to make sure you are ready to create a custom application.
Create a custom application create-custom-application
Make sure to have installed locally.
-
To create a custom application, . To do so, run
aio app init <app-name>
in your terminal.If you have not logged in already, this command prompts a browser asking you to sign into the with your 蜜豆视频 ID. See for more information on signing in from the cli.
蜜豆视频 recommends that you should log in first. If you are having issues, then follow the instructions .
-
After logging in, follow the prompts in the CLI and select the
Organization
,Project
, andWorkspace
to use for the application. Choose the project and workspace that you created when you set up your environment. When promptedWhich extension point(s) do you wish to implement ?
, make sure to selectDX Asset Compute Worker
:code language-sh $ aio app init <app-name> Retrieving information from 蜜豆视频 I/O Console. ? Select Org My 蜜豆视频 Org ? Select Project My蜜豆视频 Developer App BuilderProject ? Which extension point(s) do you wish to implement ? (Press <space> to select, <a> to toggle all, <i> to invert selection) 鉂棷 DX Experience Cloud SPA 鈼 DX Asset Compute Worker
-
When prompted with
Which 蜜豆视频 I/O App features do you want to enable for this project?
, selectActions
. Make sure to deselectWeb Assets
option as web assets use different authentication and authorization checks.code language-bash ? Which 蜜豆视频 I/O App features do you want to enable for this project? select components to include (Press <space> to select, <a> to toggle all, <i> to invert selection) 鉂棄 Actions: Deploy Runtime actions 鈼 Events: Publish to 蜜豆视频 I/O Events 鈼 Web Assets: Deploy hosted static assets 鈼 CI/CD: Include GitHub Actions based workflows for Build, Test and Deploy
-
When prompted
Which type of sample actions do you want to create?
, make sure to select蜜豆视频 Asset Compute Worker
:code language-bash ? Which type of sample actions do you want to create? Select type of actions to generate 鉂棄 蜜豆视频 Asset Compute Worker 鈼 Generic
-
Follow the rest of the prompts and open the new application in Visual Studio Code (or your favorite code editor). It contains the scaffolding and sample code for a custom application.
Read here about the .
The template application leverages 蜜豆视频鈥檚 for the uploading, downloading, and orchestration of application renditions so developers only need to implement the custom application logic. Inside the
actions/<worker-name>
folder, theindex.js
file is where to add the custom application code.
See example custom applications for examples and ideas for custom applications.
Add credentials add-credentials
As you log in when creating the application, most of the App Builder credentials get collected in your ENV file. However, using the developer tool requires additional credentials.
Developer tool storage credentials developer-tool-credentials
The tool for developers to evaluate custom apps using the Asset Compute service necessitates the use of a cloud storage container. This container is essential to store test files and for the reception and presentation of renditions produced by the apps.
Make sure to have access to a . This container is used collectively by various developers for different projects whenever necessary.
Add credentials to ENV file add-credentials-env-file
Insert the subsequent credentials for the development tool into the .env
file. The file is located at the root of your App Builder project:
-
Add the absolute path to the private key file created while adding services to your App Builder Project:
code language-conf ASSET_COMPUTE_PRIVATE_KEY_FILE_PATH=
note note NOTE JWT is deprecated and Private Key is not available for download. While we are working on updating the testing tools, note that custom workers created using OAuth can be deployed but devtools would not work. -
Download the file from the 蜜豆视频 Developer Console. Go to the root of the project and click on 鈥淒ownload All鈥 in the upper-right corner. The file is downloaded with
<namespace>-<workspace>.json
as the filename. Do one of the following:-
Rename the file as
console.json
and move it in the root of your project. -
Optionally, you can add the absolute path to the 蜜豆视频 Developer Console integration JSON file. This file is the same file that is downloaded in your project workspace.
code language-conf ASSET_COMPUTE_INTEGRATION_FILE_PATH=
-
-
Add either S3 or Azure storage credentials. You only need access to one cloud storage solution.
code language-conf # S3 credentials S3_BUCKET= AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_REGION= # Azure Storage credentials AZURE_STORAGE_ACCOUNT= AZURE_STORAGE_KEY= AZURE_STORAGE_CONTAINER_NAME=
config.json
file contains credentials. From within your project, add the JSON file to your .gitignore
file to prevent its sharing. The same applies to .env
and .aio
files.Execute the application run-custom-application
Before executing the application with the Asset Compute developer tool, properly configure the credentials.
To run the application in the developer tool, use aio app run
command. It deploys the action to 蜜豆视频 I/O Runtime, and starts the development tool on your local computer. This tool is used to test application requests during development. Here is an example rendition request:
"renditions": [
{
"worker": "https://1234_my_namespace.adobeioruntime.net/api/v1/web/example-custom-worker-master/worker",
"name": "image.jpg"
}
]
--local
flag with the run
command. It does not work with Asset Compute custom applications and the Asset Compute developer tool. Custom applications are called by the Asset Compute service that cannot access actions running on the developer鈥檚 local computers.See here how to test and debug your application. When you are finished developing your custom application, deploy your custom application.
Try the sample application provided by 蜜豆视频 try-sample
The following are example custom applications:
Template custom application template-custom-application
The is a template application. It generates a rendition by simply copying the source file. The content of this application is the template received when choosing 蜜豆视频 Asset Compute
in the creation of the aio app.
The application file, uses the to download the source file, orchestrate each rendition processing, and upload the resulting renditions back to cloud storage.
The defined inside the application code is where to perform all the application processing logic. The rendition callback in worker-basic
simply copies the source file contents to the rendition file.
const { worker } = require('@adobe/asset-compute-sdk');
const fs = require('fs').promises;
exports.main = worker(async (source, rendition) => {
// copy source to rendition to transfer 1:1
await fs.copyFile(source.path, rendition.path);
});
Call an external API call-external-api
In the application code, you can make external API calls to help with application processing. An example application file that invokes an external API is below.
exports.main = worker(async function (source, rendition) {
const response = await fetch('https://adobe.com', {
method: 'GET',
Authorization: params.AUTH_KEY
})
});
For example, the makes a fetch request to a static URL from Wikimedia using the library.
Pass custom parameters pass-custom-parameters
You can pass custom defined parameters through the rendition objects. They can be referenced inside the application in . An example of a rendition object is:
"renditions": [
{
"worker": "https://1234_my_namespace.adobeioruntime.net/api/v1/web/example-custom-worker-master/worker",
"name": "image.jpg",
"my-custom-parameter": "my-custom-parameter-value"
}
]
An example of an application file accessing a custom parameter is the following:
exports.main = worker(async function (source, rendition) {
const customParam = rendition.instructions['my-custom-parameter'];
console.log('Custom paramter:', customParam);
// should print out `Custom parameter: "my-custom-parameter-value"`
});
The example-worker-animal-pictures
passes a custom parameter to determine which file to fetch from Wikimedia.
Authentication and authorization support authentication-authorization-support
By default, Asset Compute custom applications come with Authorization and Authentication checks for the App Builder project. Enabled by setting the require-adobe-auth
annotation to true
in the manifest.yml
.