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.
data = json.loads(to_str(request.data))
    arn = func_arn(function)
    
    LAMBDA_EXECUTOR.cleanup(arn)
    lambda_details = arn_to_lambda[arn]
    if data.get('Handler'):
        lambda_details.handler = data['Handler']
    if data.get('Runtime'):
        lambda_details.runtime = data['Runtime']
    env_vars = data.get('Environment', {}).get('Variables')
    if env_vars is not None:
        lambda_details.envvars = env_vars
    if data.get('Timeout'):
        lambda_details.timeout = data['Timeout']
    return jsonify(data)
@app.route('%s/functions/<function>/policy' % PATH_ROOT, methods=['POST'])
def add_permission(function):
    data = json.loads(to_str(request.data))
    iam_client = aws_stack.connect_to_service('iam')
    sid = short_uid()
    policy = {
        'Version': IAM_POLICY_VERSION,
        'Id': 'LambdaFuncAccess-%s' % sid,
        'Statement': [{
            'Sid': sid,
            'Effect': 'Allow',
            
            
            'Action': data.get('Action'),
            'Resource': func_arn(function)