Repository navigation
Expand file tree
/
Copy pathbatch_hello.py
More file actions
54 lines (42 loc) · 1.54 KB
/
Copy pathbatch_hello.py
File metadata and controls
54 lines (42 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
"""
Purpose: Hello AWS Batch example.
Lists all compute environments in the account/region.
"""
import logging
import boto3
from botocore.exceptions import ClientError
logger = logging.getLogger(__name__)
# snippet-start:[python.example_code.batch.Hello]
def hello_batch() -> None:
"""
Lists compute environments using the AWS Batch service.
"""
batch_client = boto3.client("batch")
print("Hello, AWS Batch! Let's list your compute environments:\n")
try:
response = batch_client.describe_compute_environments()
environments = response.get("computeEnvironments", [])
if environments:
print(f"Found {len(environments)} compute environment(s):")
for env in environments:
print(
f" - Name: {env['computeEnvironmentName']} | "
f"Type: {env.get('type', 'N/A')} | "
f"State: {env.get('state', 'N/A')} | "
f"Status: {env.get('status', 'N/A')}"
)
else:
print("No compute environments found in your account.")
except ClientError as err:
logger.error(
"Error listing compute environments: %s",
err.response["Error"]["Message"],
)
raise
print("\nHello example complete.")
# snippet-end:[python.example_code.batch.Hello]
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
hello_batch()