def get_accounts_permissions(accounts):
    """Generates a CloudFormation snippet containing the permission for each AWS account.

    Args:
        accounts: List of AWS account ids

    Returns:
        CloudFormation snippet
    """
    permissions = ""

    for account in accounts:
        template = \
"""  Permission{account}:
    Type: AWS::Lambda::Permission
    DependsOn: LambdaFunction
    Properties:
      FunctionName: !Ref LambdaFunction
      Action: lambda:InvokeFunction
      Principal: config.amazonaws.com
      SourceAccount: "{account}"

"""
        permissions += template.replace("{account}", account)

    return permissions