Services
Import the services module and instantiate a service
client
[ ]:
from peak.resources import services
service_client = services.get_client()
Possible field values
Service type
The type of the service. The following types are supported: web-app
, api
and shiny
.
Status
The status of the service. The following statuses are supported: CREATING
, DEPLOYING
, AVAILABLE
, DELETING
, CREATE_FAILED
and DELETE_FAILED
.
List all existing services
(s) and iterate over them
[ ]:
services_list_iterator = service_client.list_services(status=["CREATING", "AVAILABLE"])
services_list_iterated = next(services_list_iterator)
"""
The list of services will be returned in the following format:
{
"pageCount": 1,
"pageNumber": 1,
"pageSize": 25,
"webapps": [
{
"id": "84a41de7-d67f-4aa0-aebe-83c1474f0eaf",
"name": "customerpurchases",
"status": "AVAILABLE",
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "john.doe@peak.ai",
"updatedAt": "2020-01-01T18:00:00.000Z",
"updatedBy": "john.doe@peak.ai",
"serviceType": "web-app",
"tags": [
{
"name": "foo"
},
{
"name": "bar"
}
]
}
],
"webappsCount": 40
}
"""
Prepare the payload and submit a new Service
resource for creation
[ ]:
body = {
"name": "service101",
"title": "Hello from SDK",
"description": "Hi there",
"serviceType": "web-app",
"imageDetails": { ## If versionId is not passed, service will be created using latest ready version of the image
"imageId": 123,
"versionId": 100,
},
"resources": {
"instanceTypeId": 43,
},
"parameters": {
"env": {
"param1": "value1",
"param2": "value2",
},
"secrets": ["secret1", "secret2"],
},
"sessionStickiness": True, # Not required for "api" type services
"entrypoint": "python\nmain.py",
"healthCheckURL": "/health",
"minInstances": 1,
}
created_service = service_client.create_service(body)
Modify the payload and update the existing Service
resource
[ ]:
updated_body = {
"title": "Updated title",
"description": "Updated Description",
"imageDetails": { ## If versionId is not passed, service will be updated using latest ready version of the image
"imageId": 123,
"versionId": 101,
},
"resources": {
"instanceTypeId": 43,
},
"parameters": {
"env": {
"param1": "value1",
"param2": "value2",
},
"secrets": ["secret1", "secret2"],
},
"sessionStickiness": True, # Not required for "api" type services
"entrypoint": "python\nmain.py",
"healthCheckURL": "/health",
"minInstances": 1,
}
updated_service = service_client.update_service(service_id="your-service-id", body=updated_body)
Create or update a Service
resource
[ ]:
## If service exists, it will be updated, else new service will be created
body = {
"name": "service101",
"title": "Hello from SDK",
"description": "Hi there",
"serviceType": "web-app",
"imageDetails": { ## If versionId is not passed, service will be created or updated using latest ready version of the image
"imageId": 123,
"versionId": 100,
},
"resources": {
"instanceTypeId": 43,
},
"parameters": {
"env": {
"param1": "value1",
"param2": "value2",
},
"secrets": ["secret1", "secret2"],
},
"sessionStickiness": True, # Not required for "api" type services
"entrypoint": "python\nmain.py",
"healthCheckURL": "/health",
"minInstances": 1,
}
created_service = service_client.create_or_update_service(body)
Prepare the payload for testing api
type Service
resource
[ ]:
body = {
"httpMethod": "post",
"path": "/health",
"payload": {
"id": 1,
"name": "test",
},
}
response = service_client.test_service(body=body, service_name="your-service-name")
Delete an existing Service
resource
[ ]:
service_client.delete_service(service_id="your-service-id")
Describe an existing Service
resource
[ ]:
service_client.describe_service(service_id="your-service-id")
"""
The service details will be returned in the following format:
{
"id": "84a41de7-d67f-4aa0-aebe-83c1474f0eaf",
"name": "customerpurchases",
"status": [
"string"
],
"imageDetails": {
"imageId": 1,
"versionId": 1
},
"parameters": {
"env": {...},
"secrets": [...]
},
"resources": {
"instanceTypeId": 1
},
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "john.doe@peak.ai",
"updatedAt": "2020-01-01T18:00:00.000Z",
"updatedBy": "john.doe@peak.ai",
"tags": [
{
"name": "foo"
},
{
"name": "bar"
}
],
"serviceType": "web-app",
"entrypoint": "python main.py",
"healthCheckURL": "/health",
"minInstances": 1
}
"""