<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_permission_for_apigateway(self, function_name, region_name, account_id, rest_api_id, random_id=None):
 # type: (str, str, str, str, Optional[str]) -> None """Authorize API gateway to invoke a lambda function is needed. This method will first check if API gateway has permission to call the lambda function, and only if necessary will it invoke """

        source_arn = self._build_source_arn_str(region_name, account_id,
                                                rest_api_id)
        self._add_lambda_permission_if_needed(
            source_arn=source_arn,
            function_arn=function_name,
            service_name='apigateway',
        )