When you create a Lambda permission you send the __statement id__ as mandatory parameter.

https://docs.aws.amazon.com/lambda/latest/dg/API_AddPermission.html#API_AddPermission_RequestSyntax

However this id is generated by a random value. 

https://github.com/localstack/localstack/blob/b3917bf248b77ced8ef80a3d5c0561960066db5d/localstack/services/awslambda/lambda_api.py#L927

Due to this problem, the tools like Terraform or Ansible fail when it has to be retrieved to check the existence of this element.

If you agree I could make a PR with the fix and its test.
:param zip_file_content: ZIP file bytes.
    :type handler: str
    :param handler: The lambda handler path.
    :type main_file: str
    :param main_file: Filepath to the uploaded ZIP or JAR file.
    :returns: function or flask.Response
    """
    if not is_jar_archive(zip_file_content):
        with zipfile.ZipFile(BytesIO(zip_file_content)) as zip_ref:
            jar_entries = [e for e in zip_ref.infolist() if e.filename.endswith('.jar')]
            if len(jar_entries) != 1:
                raise ClientError('Expected exactly one *.jar entry in zip file, found %s' % len(jar_entries))
            zip_file_content = zip_ref.read(jar_entries[0].filename)
            LOG.info('Found jar file %s with %s bytes in Lambda zip archive' %
                     (jar_entries[0].filename, len(zip_file_content)))
            main_file = new_tmp_file()
            save_file(main_file, zip_file_content)
    if is_jar_archive(zip_file_content):
        def execute(event, context):
            result, log_output = lambda_executors.EXECUTOR_LOCAL.execute_java_lambda(
                event, context, handler=handler, main_file=main_file)
            return result
        return execute, zip_file_content
    raise ClientError(error_response(
        'Unable to extract Java Lambda handler - file is not a valid zip/jar file', 400, error_type='ValidationError'))
def set_archive_code(code, lambda_name, zip_file_content=None):
    
    lambda_arn = func_arn(lambda_name)
    lambda_details = arn_to_lambda[lambda_arn]
    is_local_mount = code.get('S3Bucket') == BUCKET_MARKER_LOCAL