Example
Create APIs that process your workloads asynchronously.
Implementation
Create a folder for your API. In this case, we are deploying an iris-classifier AsyncAPI. This folder will have the following structure:
We will now create the necessary files:
Deploy
We can now deploy our API with the cortex deploy
command. This command can be re-run to update your API configuration or handler implementation.
Monitor
To check whether the deployed API is ready, we can run the cortex get
command with the --watch
flag.
Submit a workload
Now we want to submit a workload to our deployed API. We will start by creating a file with a JSON request payload, in the format expected by our iris-classifier
handler implementation.
This is the JSON file we will submit to our iris-classifier API.
Once we have our sample request payload, we will submit it with a POST
request to the endpoint URL previously displayed in the cortex get
command. We will quickly get a request id
back.
Retrieve the result
The obtained request id will allow us to check the status of the running payload and retrieve its result. To do so, we submit a GET
request to the same endpoint URL with an appended /<id>
.
Depending on the status of your workload, you will get different responses back. The possible workload status are in_queue | in_progress | failed | completed
. The result
and timestamp
keys are returned if the status is completed
. The result will remain queryable for 7 days after the request was completed.
It is also possible to setup a webhook in your handler to get the response sent to a pre-defined web server once the workload completes or fails. You can read more about it in the webhook documentation.
Stream logs
If necessary, you can stream the logs from a random running pod from your API with the cortex logs
command. This is intended for debugging purposes only. For production logs, you can view the logs in cloudwatch logs.
Delete the API
Finally, you can delete your API with a simple cortex delete
command.
Last updated