Or better yet, once in court and under questioning invoke the 5th Amendment. It does work once there. It cannot be used to trump a subpoena and skip out on testifying as a witness.
Until they give you a grant of immunity. Then it doesn't work anymore.
There are two kinds of immunity: Transactional immunity (witness can not ever be prosecuted for crimes related to his testimony) and Use immunity (they can't use your testimony, or any evidence they gather based on its information, against you - but if they find other evidence you're fair game.)
Unfortunately the Supreme Court has ruled that Use Immunity is enough to extinguish the 5th Amendment right and federal prosecutors rarely offer Transactional. Some states have more stringent laws, constitutions, or constitutional interpretations and Transactional immunity must be offered before their courts may compel testimony.
Of course prosecution is not the only life risk for a witness. I know of at least one person, here in the disarmed-citizen utopia of California who has stated an intent to "not have seen anything" unless granted a perpetual concealed carry license.