2023-04-24 06:51:46 -05:00
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
# snippet-start:[python.example_code.support.Hello]
import logging
import boto3
from botocore . exceptions import ClientError
logger = logging . getLogger ( __name__ )
2023-10-18 10:35:05 -07:00
2023-04-24 06:51:46 -05:00
def hello_support ( support_client ) :
"""
Use the AWS SDK for Python (Boto3) to create an AWS Support client and count
the available services in your account.
This example uses the default settings specified in your shared credentials
and config files.
:param support_client: A Boto3 Support Client object.
"""
try :
print ( " Hello, AWS Support! Let ' s count the available Support services: " )
response = support_client . describe_services ( )
print ( f " There are { len ( response [ ' services ' ] ) } services available. " )
except ClientError as err :
2023-10-18 10:35:05 -07:00
if err . response [ " Error " ] [ " Code " ] == " SubscriptionRequiredException " :
logger . info (
" You must have a Business, Enterprise On-Ramp, or Enterprise Support "
" plan to use the AWS Support API. \n \t Please upgrade your subscription to run these "
" examples. "
)
2023-04-24 06:51:46 -05:00
else :
logger . error (
" Couldn ' t count services. Here ' s why: %s : %s " ,
2023-10-18 10:35:05 -07:00
err . response [ " Error " ] [ " Code " ] ,
err . response [ " Error " ] [ " Message " ] ,
)
2023-04-24 06:51:46 -05:00
raise
2023-10-18 10:35:05 -07:00
if __name__ == " __main__ " :
hello_support ( boto3 . client ( " support " ) )
2023-04-24 06:51:46 -05:00
# snippet-end:[python.example_code.support.Hello]