Skip to main content

Run DB2Rest as Tembo Application Service

Tembo allows running DB2Rest right next to the PostGreSQL instance as an application service. This is very secure (backed by secure API Gateway) and because of close-proximity to the database provides exceptional performance. More details of Tembo application service can be read here

Deploy DB2Rest as Application Service

DB2Rest docker image can be used to deploy and run as an application service on Tembo Cloud. The Tembo REST API can be called (for now) to deploy the image. In order to use the API, a JSON Web Token JWT or API Key has to be created here. The same API Key will be used later to test the setup. Hence, it is important to save this token.

Invoke Tembo API


curl --request PATCH \
--url https://api.tembo.io/api/v1/orgs/<TEMBO_ORG_ID>/instances/<TEMBO_DB_INSTANCE_ID> \
--header 'Authorization: <JWT_TOKEN>' \
--header 'Content-Type: application/json' \
--header 'User-Agent: insomnia/8.6.1' \
--data '{
"app_services": [
{
"custom": {
"image": "registry.hub.docker.com/kdhrubo/db2rest",
"name": "db2rest",
"routing": [
{
"port": 8080,
"ingressPath": "/"
}
],
"env": [
{
"name": "DB_URL",
"value": "<JDBC_URL>"
},
{
"name": "DB_USER",
"value": "<DB_USER>"
},
{
"name": "DB_PASSWORD",
"value": "<DB_PASSWORD>"
}
],
"resources": {
"requests": {
"cpu": "500m",
"memory": "1500Mi"
},
"limits": {
"cpu": "4000m",
"memory": "1500Mi"
}
},
"storage": {
"volumeMounts": [
{
"name": "db2rest-vol",
"mountPath": "/tmp"
}
],
"volumes": [
{
"ephemeral": {
"volumeClaimTemplate": {
"spec": {
"accessModes": [
"ReadWriteOnce"
],
"resources": {
"requests": {
"storage": "2Gi"
}
}
}
}
},
"name": "db2rest-vol"
}
]
}
}
}
]
}'


Use either cURL or httpie to execute the commands above. If everything goes well, then Tembo API will respond with HTTP 202 (ACCEPTED) status code. This means within seconds DB2Rest is going to run as an application service with Tembo PostgreSQL instance.

Verify DB2Rest Application Service

It is very easy to verify DB2Rest application service with the actuator endpoint as shown below:


curl --request GET \
--url https://[TEMBO_DB_INSTANCE_ENDPOINT]/actuator/health \
--header 'Authorization: [JWT_TOKEN]' \
--header 'User-Agent: insomnia/8.6.1'


The actuator health check service in DB2Rest will return the following response:

HTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked

{
"status": "UP",
"groups": [
"liveness",
"readiness"
]
}

The status attribute shows that, the application service is ready to handle database operations.

Query DB2Rest Application Service

In the previous tutorial Integrate with Tembo, the employee table was created on Tembo PostgreSQL instance and a new row was inserted using DB2Rest running locally. Now the same table can be queried using the DB2Rest running as an application service on the Tembo platform.


curl --request GET \
--url https://[TEMBO_DB_INSTANCE_ENDPOINT]/employee \
--header 'Authorization: [JWT_TOKEN]' \
--header 'User-Agent: insomnia/8.6.1'


The DB2Rest application service will respond with the only row, that was inserted in the employee table.

HTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked

[
{
"id": 3,
"first_name": "Salman",
"last_name": "Khan",
"email": "[email protected]",
"created_on": "2015-04-14T11:07:36.639+00:00"
}
]