Directus: 4. Create the service

This documentation is part of the Automate with the CLI guide. You can view the complete guide here: Start Directus, retrieve its credentials, and modify its configuration programmatically using the Stackhero CLI.

👋 Welcome to the Stackhero documentation!

Stackhero provides a Directus cloud service that is production-ready in just 2 minutes:

  • Unlimited collections, items, users, roles, API requests, and data transfers
  • Custom domain name with integrated HTTPS for secure access (for example, https://cms.your-company.com)
  • Dedicated email server for unlimited transactional and notification emails
  • Integrated Redis cache for high performance
  • Consistent performance and enhanced security thanks to private, dedicated infrastructure
  • One-click updates to keep your system up to date with minimal effort

Focus on your project, not on configuration: you can discover Stackhero's Directus cloud solution in just 5 minutes.

Below is an example script that creates a stack, adds your Directus service to it, waits for it to start, retrieves its configuration (including generated credentials), and then applies a new configuration.

#!/bin/bash
set -e

export STACKHERO_TOKEN="usr-xxxxxx:your-token"

serviceStore="directus"   # The Directus service store name (see step 2)
instance="..."                # An instance size from step 3
region="europe"               # A region name from step 3

# Create a stack for your service (uses your default organisation; add --organization if needed)
stackId=$(stackhero --format=script stack-create \
  --name="My Directus stack")
echo "Stack created: ${stackId}"

# Add Directus to the stack (names are resolved automatically)
serviceId=$(stackhero --format=script service-add \
  --stack="My Directus stack" \
  --service-store="${serviceStore}" \
  --instance="${instance}" \
  --region="${region}")
echo "Service added: directus"

# Wait for the service to be fully operational (this may take a few minutes)
stackhero service-wait-for --service="directus"

# Retrieve the service configuration, including generated credentials
stackhero service-configuration-get --service="directus" --format=json