def validate_function_name(function_name): if not StrUtils.find_expression(function_name, VALID_LAMBDA_NAME_REGEX): error_msg = ("Find name restrictions in: https://docs.aws.amazon.com/lambda/latest/" "dg/API_CreateFunction.html#SSS-CreateFunction-request-FunctionName") raise ValidatorError(parameter='function_name', parameter_value=function_name, error_msg=error_msg)
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 get_user_info(self) -> Dict: """Retrieves information about the specified IAM user, including the user's creation date, path, unique ID, and ARN.""" try: return self.client.get_user() except ClientError as cerr: if cerr.response['Error']['Code'] == 'AccessDenied': # If the user doesn't have access rights to IAMClient # we can find the user name in the error response user_name = StrUtils.find_expression(str(cerr), self._USER_NAME_REGEX) return { 'UserName': user_name, 'User': { 'UserName': user_name, 'UserId': '' } } raise cerr except Exception as ex: raise GetUserInfoError(error_msg=ex)
def _add_account_id(resources_info: Dict): resources_info['iam']['account_id'] = StrUtils.find_expression( resources_info['iam']['role'], _ACCOUNT_ID_REGEX)
def _add_account_id(self): self.aws_properties.account_id = StrUtils.find_expression(self.aws_properties.iam.role, _ACCOUNT_ID_REGEX)