MySQL service integration example
This example shows how to integrate a MySQL service into an application.
How it works
The service configuration references an instance of the MySQL database engine with specific attributes necessary for connectivity and operation.
Diagram overview
Diagram breakdown
Service: MySQL database engine
This service refers to a MySQL database instance, which includes key parameters for connecting to the database:
Attributes:
- Host: The address of the MySQL database server.
- Port: The port number used for MySQL connections.
Links: development and production environments
The MySQL service is linked to the application through two environments, each with its own configuration:
-
Development link - properties:
- Database: The development database name.
- Username: Credential for accessing the MySQL database in development.
- Password: Password for the development database.
-
Production ink - properties:
- Database: The production database name.
- Username: Credential for accessing the MySQL database in production.
- Password: Password for the production database.
Automatic parameter integration
When the application connects to the MySQL service, the following parameters are automatically used in its configuration:
- Host: From the service's host attribute.
- Port: From the service's port attribute.
- User: From the link's username (either development or production).
- Pass: From the link's password (either development or production).
- Name: From the link's database (either development or production).
This setup helps manage MySQL database connections in a straightforward way, ensuring that configurations can easily switch between development and production environments.
Creating the specifications
Involves setting attributes and constraints that a service must meet.
Service specification
The example below shows how to create a MySQL service specification tailored to your organization's settings, focusing on visibility, reuse, and parameter configuration.
{
"name": "MySQL",
"visible_to": ["organization=12345:account=12345:namespace=28"],
"attributes" : {
"schema": {
"type": "object",
"required": ["host", "port"],
"properties": {
"host": {
"type": "string",
"export": true,
"readOnly": true
},
"port": {
"type": "integer",
"export": true,
"default": 3306,
"readOnly": true
},
},
"additionalProperties": false
},
"values": {}
},
"selectors": {
"category": "Database",
"imported": false,
"provider": "AWS",
"sub_category": "Relational Database"
}
}
-
visible_to
: This service is exclusively visible within the namespace28
of the specified organization and account:organization=12345:account=12345:namespace=28
. -
attributes
specification specifies the essential connection details required by any application utilizing this service:- Host: The hostname or IP address of the MySQL database server.
- Port: The port number used by the MySQL database server to accept connections.
For more details, refer to Create service specification in our API docs.
Link specification
This example shows how to define who can access a service, under what conditions, and with which attributes (such as database schema, username, and password).
{
"name": "Link MySQL Database",
"unique": false,
"attributes" : {
"schema": {
"type": "object",
"required": ["username", "password", "name"],
"properties": {
"name": {
"type": "string",
"export": true,
"readOnly": true
},
"password": {
"type": "string",
"export": {
"type": "environment_variable",
"secret": true
},
"readOnly": true
},
"username": {
"type": "string",
"export": true,
"readOnly": true
}
},
"additionalProperties": false
},
"values": {}
},
"specification_id": "afe74a12-0d28-4b41-8f25-8b58b2f09186"
}
In this example, a link for a MySQL service is defined with key attributes like name
, username
, and password
. It also specifies which attributes should be exported as parameters in the service configuration.
For more details, refer to Create a link specification in our API docs.
Action specification
This example shows how to configure an action specification for your MySQL service.
{
"name": "My MySQL service action",
"slug": "my-sql-service-action",
"type": "create",
"parameters": {
"schema": {
"required": [
"size"
],
"properties": {
"size": {
"type": "string",
"enum": ["small", "medium", "large"]
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"required": ["host", "port"],
"properties": {
"host": {
"type": "string",
"export": true,
"readOnly": true
},
"port": {
"type": "integer",
"export": true,
"default": 3306,
"readOnly": true
}
},
"additionalProperties": false
},
"values": {}
}
}'
For more details, refer to our action specification API docs.
Security and permissions
Each defined element comes with its own permissions and access control, allowing for the management of who can create and use resources and where these resources can be deployed.