MCPcopy Create free account
hub / github.com/awsdocs/aws-doc-sdk-examples / OpsItemWrapper

Class OpsItemWrapper

python/example_code/ssm/ops_item.py:14–154  ·  view source on GitHub ↗

Encapsulates AWS Systems Manager OpsItem actions.

Source from the content-addressed store, hash-verified

12# snippet-start:[python.example_code.ssm.OpsItemWrapper.class]
13# snippet-start:[python.example_code.ssm.OpsItemWrapper.decl]
14class OpsItemWrapper:
15 """Encapsulates AWS Systems Manager OpsItem actions."""
16
17 def __init__(self, ssm_client):
18 """
19 :param ssm_client: A Boto3 Systems Manager client.
20 """
21 self.ssm_client = ssm_client
22 self.id = None
23
24 @classmethod
25 def from_client(cls):
26 """
27 :return: A OpsItemWrapper instance.
28 """
29 ssm_client = boto3.client("ssm")
30 return cls(ssm_client)
31
32 # snippet-end:[python.example_code.ssm.OpsItemWrapper.decl]
33
34 # snippet-start:[python.example_code.ssm.CreateOpsItem]
35 def create(self, title, source, category, severity, description):
36 """
37 Create an OpsItem
38
39 :param title: The OpsItem title.
40 :param source: The OpsItem source.
41 :param category: The OpsItem category.
42 :param severity: The OpsItem severity.
43 :param description: The OpsItem description.
44
45 """
46 try:
47 response = self.ssm_client.create_ops_item(
48 Title=title,
49 Source=source,
50 Category=category,
51 Severity=severity,
52 Description=description,
53 )
54 self.id = response["OpsItemId"]
55 except self.ssm_client.exceptions.OpsItemLimitExceededException as err:
56 logger.error(
57 "Couldn't create ops item because you have exceeded your open OpsItem limit. "
58 "Here's why: %s: %s",
59 err.response["Error"]["Code"],
60 err.response["Error"]["Message"],
61 )
62 raise
63 except ClientError as err:
64 logger.error(
65 "Couldn't create ops item %s. Here's why: %s: %s",
66 title,
67 err.response["Error"]["Code"],
68 err.response["Error"]["Message"],
69 )
70 raise
71 # snippet-end:[python.example_code.ssm.CreateOpsItem]

Callers 4

test_create_ops_itemFunction · 0.90
test_delete_ops_itemFunction · 0.90
test_describe_ops_itemFunction · 0.90
test_update_ops_itemFunction · 0.90

Calls

no outgoing calls

Tested by 4

test_create_ops_itemFunction · 0.72
test_delete_ops_itemFunction · 0.72
test_describe_ops_itemFunction · 0.72
test_update_ops_itemFunction · 0.72