Directus: 4. Create the service

This documentation is part of the Automate with the CLI guide. View the full guide here: Start Directus, retrieve its credentials, and change its configuration programmatically with the Stackhero CLI.

👋 Welcome to the Stackhero documentation!

Stackhero offers a Directus cloud service that is ready for production use in just 2 minutes:

  • Unlimited collections, items, users, roles, API requests, and data transfers
  • Custom domain name with built-in 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 strong security with private, dedicated infrastructure
  • One-click updates let you keep your system current with minimal effort

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

Here is a sample 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 organization; 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 running (this may take a couple of minutes)
stackhero service-wait-for --service="directus"

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