Indonesian police arrested a teenager for allegedly attempting to attack a church in Medan, the capital of North Sumatra, with a homemade bomb on Sunday.

North Sumatra provincial police spokeswoman Rina Sari Ginting told The Straits Times that the 17-year-old boy was sitting among the morning mass congregation at the St. Yoseph Catholic Church.

The police said the boy, who has been identified as Ivan Armadi Hasugian from his identity card, had a backpack reportedly containing a small explosive device.

Nana Manullang, an eyewitness, who was sitting next to him, said the teenager had been "assembling a suspected bomb", comprising of a battery and a pipe hidden in a gold jacket before the attack.

She said the boy stood up, with his backpack which gave off "smoke, sparks and faint sounds of firecrackers", and rushed towards a pastor near a pulpit and attacked him.The pastor was left slightly injured in his left arm.

The eyewitness added that the boy was then restrained by the members of the congregation.

Boy Rafli Amar, the national police spokesman said the police are "examining the perpetrator's backpack". He also said that the attacker was still alive and there were no casualties.

A source close to the investigation said the police have confiscated several items, including a backpack, a knife, and a note with "La ilaha illallah" in Arabic written on it which means "there is no God but Allah".

Recently, Indonesia has been the target of several terror threats and attacks. The counter-terrorism police launched a crackdown on people with suspected links to Islamic State in Iraq and Syria (ISIS).