class DeviceFarmDevicePool(core.Construct): DEVICE_FARM_CFN_HANDLER_ACTIONS = [ "devicefarm:CreateDevicePool", "devicefarm:UpdateDevicePool", "devicefarm:DeleteDevicePool" ] device_pool_name = None device_pool_arn = None custom_resource = None def __init__(self, scope: core.Construct, id: str, project_arn: str, device_pool_name: str, manufacturer: str = 'Google', platform: str = 'ANDROID', os_version='10', max_devices=1, log_retention=None) -> None: super().__init__(scope, id) self.device_pool_name = device_pool_name policy = AwsCustomResourcePolicy.from_sdk_calls( resources=AwsCustomResourcePolicy.ANY_RESOURCE) self.custom_resource = AwsCustomResource( scope=self, id=f'{id}-CustomResource', policy=policy, log_retention=log_retention, on_create=self.create_device_pool(project_arn, device_pool_name, platform, max_devices, os_version, manufacturer), on_update=self.update_device_pool(device_pool_name, platform, max_devices, os_version, manufacturer), on_delete=self.delete_device_pool(), resource_type='Custom::AWS-DeviceFarm-DevicePool') self.device_pool_arn = self.custom_resource.get_response_field_reference( 'devicePool.arn') def create_device_pool(self, project_arn, device_pool_name, platform, max_devices, os_version, manufacturer): return AwsSdkCall( action='createDevicePool', service='DeviceFarm', parameters={ 'name': device_pool_name, 'projectArn': project_arn, 'rules': self._build_rules(platform, os_version, manufacturer), 'maxDevices': max_devices }, region= 'us-west-2', # When other endpoints become available for DF, we won't have to do this. physical_resource_id=PhysicalResourceId.from_response( "devicePool.arn")) def update_device_pool(self, device_pool_name, platform, max_devices, os_version, manufacturer): return AwsSdkCall( action='updateDevicePool', service='DeviceFarm', parameters={ 'arn': self.device_pool_arn, 'name': device_pool_name, 'rules': self._build_rules(platform, os_version, manufacturer), 'maxDevices': max_devices }, region= 'us-west-2', # When other endpoints become available for DF, we won't have to do this. physical_resource_id=PhysicalResourceId.from_response( "devicePool.arn")) def delete_device_pool(self): return AwsSdkCall( action='deleteDevicePool', service='DeviceFarm', parameters={'arn': self.device_pool_arn}, region= 'us-west-2', # When other endpoints become available for DF, we won't have to do this. physical_resource_id=PhysicalResourceId.from_response( "devicePool.arn")) def _build_rules(self, platform, os_version, manufacturer, availability='HIGHLY_AVAILABLE'): return [{ 'attribute': 'AVAILABILITY', 'operator': 'EQUALS', 'value': f"\"{availability}\"" }, { 'attribute': 'MANUFACTURER', 'operator': 'EQUALS', 'value': f"\"{manufacturer}\"" }, { 'attribute': 'PLATFORM', 'operator': 'EQUALS', 'value': f"\"{platform}\"" }, { 'attribute': 'OS_VERSION', 'operator': 'EQUALS', 'value': f"\"{os_version}\"" }]
class DeviceFarmProject(core.Construct): DEVICE_FARM_CFN_HANDLER_ACTIONS = [ "devicefarm:DeleteProject", "devicefarm:CreateProject", "devicefarm:UpdateProject" ] project_name = None project_arn = None project_id = None custom_resource = None def __init__(self, scope: core.Construct, id: str, project_name: str, log_retention=None) -> None: super().__init__(scope, id) self.project_name = project_name policy = AwsCustomResourcePolicy.from_sdk_calls( resources=AwsCustomResourcePolicy.ANY_RESOURCE) self.custom_resource = AwsCustomResource( scope=self, id=f'{id}-CustomResource', policy=policy, log_retention=log_retention, on_create=self.create_project(project_name), on_update=self.update_project(project_name), on_delete=self.delete_project(project_name), resource_type='Custom::AWS-DeviceFarm-Project') self.project_arn = self.custom_resource.get_response_field_reference( 'project.arn') self.project_id = core.Fn.select( 6, core.Fn.split(":", core.Token.as_string(self.project_arn))) def create_project(self, project_name): return AwsSdkCall( action='createProject', service='DeviceFarm', parameters={'name': project_name}, region= 'us-west-2', # When other endpoints become available for DF, we won't have to do this. physical_resource_id=PhysicalResourceId.from_response( "project.arn")) def update_project(self, project_name): return AwsSdkCall( action='updateProject', service='DeviceFarm', parameters={ 'name': project_name, 'arn': self.project_arn }, region= 'us-west-2', # When other endpoints become available for DF, we won't have to do this. physical_resource_id=PhysicalResourceId.from_response( "project.arn")) def delete_project(self, project_name): return AwsSdkCall( action='deleteProject', service='DeviceFarm', parameters={'arn': self.project_arn}, region= 'us-west-2', # When other endpoints become available for DF, we won't have to do this. physical_resource_id=PhysicalResourceId.from_response( "project.arn")) def get_arn(self): return self.project_arn def get_project_id(self): return self.project_id