Cloud 3.02

Service Configuration

Configuring services in .magento/services.yaml and connecting them via .magento.app.yaml relationships.

Exam Critical: Understanding service configuration in .magento/services.yaml and relationships in .magento.app.yaml is essential for the AD0-E717 exam! Know available services, disk configuration, and limitations.

Service Configuration

mindmap root((Services)) services.yaml Define services Set disk space Service versions app.yaml relationships Connect to services Available Services MySQL default Redis default Elasticsearch RabbitMQ Disk Configuration Minimum 256MB Can increase Cannot reduce Default 5GB project Pro Plans Support ticket needed Staging Production Tunneling Access services Debug locally

Service Configuration Overview

Two-File Configuration

Services are configured using two files:

1. .magento/services.yaml

Enables and configures services (MySQL, Redis, Elasticsearch, RabbitMQ)

  • Define service type and version
  • Set disk space allocation
  • Configure multiple instances of same service

2. .magento.app.yaml

Associates services with your application via relationships

  • Connect application to services
  • Define relationship names
  • Make services accessible to code

Available Services

Default Services

Installed by Default

  • MySQL: Primary database
  • Redis: Caching and session storage

Optional Services

Can Be Added

  • Elasticsearch: Search and catalog indexing
  • RabbitMQ: Message queue for async operations

Configuring Services in .magento/services.yaml

File Location

.magento/services.yaml

Basic Configuration

# .magento/services.yaml

elasticsearch:
    type: elasticsearch:6.5
    disk: 256

rabbitmq:
    type: rabbitmq:3.5
    disk: 256

Configuration Elements

  • Service name: Identifier for the service (e.g., elasticsearch, rabbitmq)
  • type: Service type and version (e.g., elasticsearch:6.5)
  • disk: Disk space in MB (minimum 256MB)

Service Versions

Each service supports specific versions:

Service Example Versions
MySQL 10.2, 10.3, 10.4
Redis 5.0, 6.0
Elasticsearch 6.5, 7.5, 7.7
RabbitMQ 3.5, 3.7, 3.8

Associating Services in .magento.app.yaml

Relationships Configuration

After defining services in services.yaml, connect them to your application:

File Location

.magento.app.yaml

Example Configuration

# .magento.app.yaml

relationships:
    rabbitmq: "rabbitmq:rabbitmq"
    elasticsearch: "elasticsearch:elasticsearch"

Relationship Format

relationship_name: "service_name:endpoint"

  • relationship_name: How your application references the service
  • service_name: Name defined in services.yaml
  • endpoint: Service endpoint (usually same as service type)

Complete Example

# .magento.app.yaml

name: mymagento
type: php:8.1

relationships:
    database: "mysql:mysql"
    redis: "redis:redis"
    rabbitmq: "rabbitmq:rabbitmq"
    elasticsearch: "elasticsearch:elasticsearch"

Disk Space Configuration

Disk Allocation Rules

Minimum Disk Size

256MB minimum - You will receive an error if a service's disk size is less than 256MB.

# Will cause an error
elasticsearch:
    type: elasticsearch:6.5
    disk: 128  # ❌ Too small!

# Correct
elasticsearch:
    type: elasticsearch:6.5
    disk: 256  # ✅ Minimum size

⚠️ Critical Limitation

Disk space can be INCREASED but NEVER REDUCED

Once you increase a service's disk space, it is not possible to reduce it. Plan carefully!

Example
# Initial configuration
elasticsearch:
    disk: 256

# Later increase (OK)
elasticsearch:
    disk: 512  # ✅ Allowed

# Cannot go back down
elasticsearch:
    disk: 256  # ❌ NOT ALLOWED!

Default Project Storage

Default storage per project: 5GB

This is shared across all services (MySQL, Redis, Elasticsearch, etc.) and media storage.

Multiple Service Instances

Configuring Multiple Instances

You can configure multiple instances of the same service type:

Example: Two MySQL Databases

# .magento/services.yaml

mysql:
    type: mysql:10.4
    disk: 1024

mysql_secondary:
    type: mysql:10.4
    disk: 512

Connecting Both Instances

# .magento.app.yaml

relationships:
    database: "mysql:mysql"
    database_secondary: "mysql_secondary:mysql"

Use Cases

  • Separate database for reporting/analytics
  • Multi-tenant architecture
  • Data segmentation for performance

Pro Plan Considerations

Staging and Production Updates

Support Ticket Required

Changes to .magento/services.yaml in Pro Staging or Production environments require a support ticket.

Process
  1. Update services.yaml in your code
  2. Test in Integration environment
  3. Commit and push to Git
  4. Open support ticket for Staging/Production
  5. Wait for Adobe Support to apply changes
Environment Service Changes
Starter (all) Auto-applied on merge
Pro Integration Auto-applied on merge
Pro Staging Requires support ticket
Pro Production Requires support ticket

Tunneling to Services

Accessing Services Locally

When you create an SSH tunnel, configured services are automatically exposed:

magento-cloud tunnel:open

Example Output

SSH tunnel opened on port 30000 to relationship: database
SSH tunnel opened on port 30001 to relationship: redis
SSH tunnel opened on port 30002 to relationship: elasticsearch
SSH tunnel opened on port 30003 to relationship: rabbitmq

Benefits

  • Debug services from local machine
  • Connect with local tools (MySQL Workbench, Redis Desktop Manager)
  • Test queries and configurations
  • Verify service availability

Renaming Services

⚠️ Critical Warning About Renaming

Data Loss Warning

Renaming a service DELETES all data in the old service!

What Happens
  1. Old service is deleted (data lost)
  2. New service is created (empty)
  3. Application reconnects to new service

Example

# Before
mysql:
    type: mysql:10.4
    disk: 1024

# After renaming to "database"
database:  # New name - creates NEW service
    type: mysql:10.4
    disk: 1024

# Result: All data from "mysql" service is LOST!

Safe Alternative

Instead of renaming, create a new service and migrate data manually:

  1. Add new service with different name
  2. Export data from old service
  3. Import data to new service
  4. Update relationships
  5. Remove old service (if needed)

Common Service Configurations

Complete Example: E-commerce Setup

.magento/services.yaml

# MySQL for primary database
mysql:
    type: mysql:10.4
    disk: 2048

# Redis for cache and sessions
redis:
    type: redis:6.0
    disk: 256

# Elasticsearch for catalog search
elasticsearch:
    type: elasticsearch:7.7
    disk: 1024

# RabbitMQ for async operations
rabbitmq:
    type: rabbitmq:3.8
    disk: 512

.magento.app.yaml

name: mymagento
type: php:8.1

relationships:
    database: "mysql:mysql"
    redis: "redis:redis"
    elasticsearch: "elasticsearch:elasticsearch"
    rabbitmq: "rabbitmq:rabbitmq"

Best Practices

Do's
  • Plan disk space carefully (can't reduce)
  • Use minimum 256MB per service
  • Test service changes in Integration first
  • Match service versions to Magento requirements
  • Monitor disk usage regularly
  • Use tunneling for local debugging
  • Document service configurations
  • Open support tickets for Pro Staging/Production
Don'ts
  • Don't rename services without data backup
  • Don't use less than 256MB disk
  • Don't expect to reduce disk space
  • Don't change Production without support ticket (Pro)
  • Don't forget to update app.yaml relationships
  • Don't exceed project storage limits
  • Don't use incompatible service versions

Exam Tips

Key Points to Remember

  • Two files: services.yaml (define) + app.yaml (connect via relationships)
  • Default services: MySQL and Redis installed by default
  • Optional services: Elasticsearch, RabbitMQ
  • Minimum disk: 256MB per service (error if less)
  • Disk limitation: Can increase but NEVER reduce
  • Default project storage: 5GB total
  • Multiple instances: Can configure multiple entries per service type
  • Service format: type: servicetype:version, disk: size_in_mb
  • Relationship format: name: "service:endpoint"
  • Pro plans: Staging/Production requires support ticket
  • Starter plans: Auto-applied on merge
  • Tunneling: tunnel:open exposes all configured services
  • Renaming warning: Deletes old service data completely
  • Service versions: Must match Magento compatibility