TITLE: Existence of continuous function with a compact support and nontrivial on given compact set in $\sigma$-compact space
QUESTION [6 upvotes]: The following fact is trivial to see:
Let $X$ be a separable and locally compact metric space, then for each compact set $K\subset X$ there is a continuous function with compact support and such that $f|K=1$. 
Indeed, $X=\bigcup \limits_{n=1}^{\infty} U_n$, where $\{U_n\}$ is a increasing sequence of open and precompact subset of $X$ (from the Lindelöf theorem). So there is an $m\in \mathbb{N}$, such that $K\subset U_m$. Now, applying Urysohn's theorem to the sets $K$ and $X \setminus U$, we find the suitable function (with support contained in $\operatorname{cl} U_m$, with is compact).
If something like that (or similar) would be true, when $X$ was a $\sigma$-compact Polish space?

REPLY [5 votes]: For the sake of having an answer:
Let $X$ be a Hausdorff space. Let $C_{c}(X)$ be the space of continuous functions $f$ with compact support. Put $$Y = \bigcup_{f \in C_{c}(X)} \{|f| \gt 0\}.$$ 
Then $Y \subset X$ is an open locally compact subspace.
Indeed if $Y = \emptyset$ this is clear. Otherwise for each $y \in Y$ we have  $|f(y)| \gt 0$ for some $f \in C_{c}(X)$. But then $U = \{|f| \geq |f(y)|/2\}$ is a compact neighborhood of $y$.
In other words, if $K \subset X$ is compact there exists a continuous function $f$ with compact support such that $f\,|_{K} = 1$ if and only if $K \subset Y$. 
Since you said in a comment that you want to have such a function for all compact $K \subset X$ we must have $Y = X$ and thus $X$ must be locally compact.