In a mortar and pestle or food processor, grind the red chilies, shallots, and garlic into a coarse paste. Leave some texture for added depth of flavor.
Heat the vegetable oil in a pan over medium heat. Add the ground chili paste and cook, stirring frequently, for about 5 minutes until the raw smell of the chilies dissipates.
If using shrimp paste, add it to the pan and continue stirring for another 1-2 minutes until fragrant.
Stir in the tamarind paste or juice, sugar, and salt. Adjust the seasoning according to your taste preference.
Cook the mixture for an additional 5-7 minutes, stirring occasionally, until the flavors meld together and the oil separates from the sauce.
Remove the pan from heat and let the sambal bawang cool down.
Transfer the homemade sambal bawang to a jar or airtight container for storage.