Skip to content

Commit 3d75ddc

Browse files
authored
Merge pull request #33 from stax-labs/feat/examples-tasks
feat(tasks) add read tasks to examples
2 parents c894655 + 8fb76aa commit 3d75ddc

5 files changed

Lines changed: 42 additions & 5 deletions

File tree

examples/tasks/read_tasks.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
3+
from staxapp.config import Config
4+
from staxapp.openapi import StaxClient
5+
6+
Config.access_key = os.getenv("ACCESS_KEY")
7+
Config.secret_key = os.getenv("SECRET_KEY")
8+
9+
# Read all tasks
10+
task_client = StaxClient("tasks")
11+
all_tasks = task_client.ReadTasks()
12+
print(all_tasks)
13+
14+
# Task Id in the response of a different StaxClient call
15+
task_id = <Task Id>
16+
17+
# Get a specific task
18+
task = task_client.ReadTask(task_id=task_id)
19+
print(task)

examples/workloads/create_catalogue_item.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626

2727
#Upload the cfn to the deployment bucket
2828
s3 = boto3.resource('s3')
29-
workload_client = StaxClient("workloads")
3029
cfn_name = f'{catalogue_version}-{catalogue_name}.yaml'
3130
s3.Bucket(bucket_name["Parameter"]["Value"]).upload_file(cloudformation_manifest_path, cfn_name)
3231

32+
## Invoke the Stax SDK
33+
workload_client = StaxClient("workloads")
34+
3335
# Make the cfn into a workload catalogue item
3436
manifest_body = f"""Resources:
3537
- WorkloadSSM:

examples/workloads/create_catalogue_version.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import boto3
22
from staxapp.config import Config
33
from staxapp.openapi import StaxClient
4-
4+
55
# Requirements
66
# - Logged into the deployment bucket account
77
# - Logged into the SDK
@@ -26,10 +26,12 @@
2626

2727
#Upload the cfn to the deployment bucket
2828
s3 = boto3.resource('s3')
29-
workload_client = StaxClient("workloads")
3029
cfn_name = f'{catalogue_version}-{catalogue_name}.yaml'
3130
s3.Bucket(bucket_name["Parameter"]["Value"]).upload_file(cloudformation_manifest_path, cfn_name)
3231

32+
# # Invoke the Stax SDK
33+
workload_client = StaxClient("workloads")
34+
3335
# Make the cfn into a workload catalogue item
3436
manifest_body = f"""Resources:
3537
- WorkloadSSM:

examples/workloads/create_workload.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from staxapp.openapi import StaxClient
33

44
# Requirements
5-
# - Logged into the deployment bucket account
65
# - Logged into the SDK
76

87
Config.access_key = <Access Key>
@@ -12,7 +11,7 @@
1211
catalogue_id = <Catalogue Id>
1312
workload_name = <Workload Name>
1413
account_id = <Account Id>
15-
parameter_dict = <Dictionary of Parameters
14+
parameter_dict = <Dictionary of Parameters>
1615
tags_dict = <Dictionary of Tags>
1716

1817
workload_client = StaxClient('workloads')
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from staxapp.config import Config
2+
from staxapp.openapi import StaxClient
3+
4+
Config.access_key = <Access Key>
5+
Config.secret_key = <Secret Key>
6+
7+
# The workload to update
8+
workload_id = <Workload Id>
9+
# The catalogue version id to update the worklaod too
10+
catalogue_version_id = <Catalogue Version Id>
11+
12+
workload_client = StaxClient('workloads')
13+
14+
response = workload_client.UpdateWorkload(workload_id=workload_id, catalogue_version_id=catalogue_version_id)
15+
print(response)

0 commit comments

Comments
 (0)