def get_resource_arn_list(self, iam_user_id: str, resource_type: str = 'lambda') -> List: """Returns a list of ARNs filtered by the resource_type passed and the tags created by scar.""" try: # Creation of a function_info filter by tags tag_filters = [{ 'Key': 'owner', 'Values': [iam_user_id] }, { 'Key': 'createdby', 'Values': ['scar'] }] resource_type_filters = [resource_type] tagged_resources = self.client.get_tagged_resources( tag_filters, resource_type_filters) return [ function_info['ResourceARN'] for function_info in tagged_resources ] except ClientError as cerr: logger.error("Error getting function_info arn by tag", f"Error getting function_info arn by tag: {cerr}") raise cerr
def _create_s3_buckets(self, resources_info: Dict) -> None: if resources_info.get('lambda').get('input', False): s3_service = S3(resources_info) for bucket in resources_info.get('lambda').get('input'): if bucket.get('storage_provider') == 's3': bucket_name, folders = s3_service.create_bucket_and_folders( bucket.get('path')) lambda_client = Lambda(resources_info) lambda_client.link_function_and_bucket(bucket_name) # Check if function is already available logger.info("Wait function to be 'Active'") if not lambda_client.wait_function_active( resources_info.get('lambda').get('arn')): logger.error("Timeout waiting function.") else: logger.info("Function 'Active'") s3_service.set_input_bucket_notification( bucket_name, folders) if not folders: logger.info( f'Input bucket "{bucket_name}" successfully created' ) if resources_info.get('lambda').get('output', False): s3_service = S3(resources_info) for bucket in resources_info.get('lambda').get('output'): if bucket.get('storage_provider') == 's3': bucket_name, folders = s3_service.create_bucket_and_folders( bucket.get('path')) if not folders: logger.info( f'Output bucket "{bucket_name}" successfully created' )
def _parse_error_invocation_response(response, function_name): if response: if "Task timed out" in response['Payload']: # Find the timeout time message = StrUtils.find_expression(str(response['Payload']), '(Task timed out .* seconds)') # Modify the error message to ease the error readability error_msg = message.replace("Task", "Function '%s'" % function_name) error_log = f"Error in function response: {error_msg}" else: error_msg = "Error in function response." error_log = f"Error in function response: {response['Payload']}" logger.error(error_msg, error_log)
def parse_arguments(self) -> Dict: """Command parsing and selection""" try: cmd_args = self.parser.parse_args() if cmd_args.version: print(f"SCAR {version.__version__}") sys.exit(0) cmd_args = vars(cmd_args) if 'func' not in cmd_args: raise excp.MissingCommandError() scar_args = _parse_scar_args(cmd_args) aws_args = _parse_aws_args(cmd_args) return cmd_args['func'], DataTypesUtils.merge_dicts_with_copy( scar_args, aws_args) except AttributeError as aerr: logger.error( "Incorrect arguments: use scar -h to see the options available", f"Error parsing arguments: {aerr}") except: print("Unexpected error:", sys.exc_info()[0]) raise