Amniocentesis is a diagnostic procedure that uses a needle to get a sample of amniotic fluid from the womb during pregnancy. Amniotic fluid surrounds the fetus in the womb and tests can detect many things, such as birth defects or whether a baby's lungs are mature enough to be delivered early.