Let $\Omega \subseteq \mathbb R^{N}$ be open and $K_1, K_2 \subseteq \Omega$ be compact subsets of $\Omega$ with $K_1 \cap K_2 = \varnothing.$ Then there exists a continuous function $f \in C_c (\Omega)$ with compact support contained in $\Omega$ such that $|f (x)| \leq 1$ for all $x \in \Omega$ and $f = 1$ on $K_1$ and $f = - 1$ on $K_2.$
This is almost an application of Urysohn's lemma except for the compactly supported part. Having obtained such a continuous function on $\Omega$ can we modify it further so that the resultant function is also bounded by $1$ and takes all the prescribed values on the compact sets and is compactly supported?
Edit: The version of Urysohn's lemma that I'm using is Theorem 2.12 in Rudin's Real and Complex Analysis. It says:
I would apply Urysohn's lemma twice.
$K_1$ is a compact subset of $U_1 := \Omega \setminus K_2$. By Urysohn's lemma, there exists a continuous $g_1: \Omega \to \mathbb R$ such that
Similarly, $K_2$ is a compact subset of $U_2 := \Omega \setminus K_1$, so by Urysohn's lemma, there exists a continuous $g_2 : \Omega \to \mathbb R$ such that
Finally, we define the function $f : \Omega \to \mathbb R$ by $$ f(x) = g_1 (x) - g_2(x).$$
Observe that