@@ -26,31 +26,32 @@ def is_apigw_edge_configuration_supported(cls):
26
26
]
27
27
28
28
@classmethod
29
- def is_sar_supported (cls ):
29
+ def is_service_supported (cls , service , region = None ):
30
30
"""
31
- SAR is not supported in some regions.
31
+ Not all services are supported in all regions. This method returns whether a given
32
+ service is supported in a given region. If no region is specified, the current region
33
+ (as identified by boto3) is used.
32
34
https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/
33
- https://docs.aws.amazon.com/general/latest/gr/serverlessrepo.html
34
35
35
- :return: True, if SAR is supported in current region.
36
+ :param service: service code (string used to obtain a boto3 client for the service)
37
+ :param region: region identifier (e.g., us-east-1)
38
+ :return: True, if the service is supported in the region
36
39
"""
37
40
38
41
session = boto3 .Session ()
39
42
40
- # get the current region
41
- region = session .region_name
43
+ if not region :
44
+ # get the current region
45
+ region = session .region_name
42
46
43
- # need to handle when region is None so that it won't break
44
- if region is None :
45
- if ArnGenerator .BOTO_SESSION_REGION_NAME is not None :
46
- region = ArnGenerator .BOTO_SESSION_REGION_NAME
47
- else :
48
- raise NoRegionFound ("AWS Region cannot be found" )
47
+ # need to handle when region is None so that it won't break
48
+ if region is None :
49
+ if ArnGenerator .BOTO_SESSION_REGION_NAME is not None :
50
+ region = ArnGenerator .BOTO_SESSION_REGION_NAME
51
+ else :
52
+ raise NoRegionFound ("AWS Region cannot be found" )
49
53
50
- # boto3 get_available_regions call won't return us-gov and cn regions even if SAR is available
51
- if region .startswith ("cn" ) or region .startswith ("us-gov" ):
52
- return True
53
-
54
- # get all regions where SAR are available
55
- available_regions = session .get_available_regions ("serverlessrepo" )
54
+ # check if the service is available in region
55
+ partition = session .get_partition_for_region (region )
56
+ available_regions = session .get_available_regions (service , partition_name = partition )
56
57
return region in available_regions
0 commit comments