Services
Import the services module and instantiate a service
client
[ ]:
from peak.resources import services
service_client = services.get_client()
List all existing services
(s) and iterate over them
[ ]:
services_list_iterator = service_client.list_services(
status=["CREATING"],
name="test",
)
services_list_iterated = next(services_list_iterator)
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")