(Deuteronomy 25:17:) "Amalek" ('amaleq). A people that licked ('am laq); it spread out like the zachla-locust. Another interpretation: "Amalek" — a people that licks ('am leq), a nation that came to lap up the blood of Israel like a dog. Rabbi Levi said in the name of Rabbi Shimon ben Chalafta: To what was Amalek comparable? To a fly that is greedy after the wound. So was Amalek greedy after Israel like a dog. It was taught in the name of Rabbi Natan: Amalek came four hundred parasangs to wage war with Israel at Rephidim, as it is said (Numbers 13:29): "Amalek dwells in the land of the Negev," and he [dwells] in front of all of them. "On the way as you came out of Egypt" (Deuteronomy 25:17). Rabbi Levi said: He came upon them from the road like a brigand. A parable: to a king who had a vineyard, and he surrounded it with a fence, and the king set within it a biting dog. The king said: Anyone who comes and breaches the fence, the dog will bite him. In time the king's son came and breached the fence, and the dog bit him. Whenever [the king] sought to recall the sin of his son who had breached the vineyard, he would say to him: Do you remember that the dog bit you? So too, whenever the Holy One, blessed be He, seeks to recall the sin of Israel — what they did at Rephidim, when they said (Exodus 17:7), "Is the LORD in our midst or not?" — He says to them: "Remember what Amalek did to you."
Why Amalek Came Four Hundred Parasangs to Attack Israel
Midrash Tanchuma Buber, Ki Teitzei 12:1
עמלק (דברים כה יז). עם לק פרח כזחלא. ד"א עמלק, עם לק, אומה שבא ללוק דמן של ישראל ככלב, ר' לוי בשם ר' שמעון בן חלפתא אמר למה היה עמלק דומה, לזבוב שהוא להוט אחר המכה, כך היה עמלק להוט אחר ישראל ככלב, תני בשם ר' נתן ארבע מאות פרסה בא עמלק להלחם עם ישראל ברפידים, שנאמר עמלק יושב בארץ הנגב וגו' (במדבר יג כט), והוא [יושב] לפנים מכולם. בדרך בצאתכם ממצרים (דברים כה יז), אמר ר' לוי מן הדרך בא עליהם כליסטים, משל למלך שהיה לו כרם, והקיפו גדר, והושיב בו המלך כלב נשכן, אמר המלך כל מי שיבא ויפרוץ הגדר ינשכו הכלב, לימים בא בנו של מלך, ופרץ הגדר, נשכו הכלב, כל מקום שהיה מבקש להזכיר חטא של בנו שפרץ הכרם, אמר לו זכור אתה שנשכך הכלב, כך כל זמן שהקב"ה מבקש להזכיר חטאן של ישראל, מה שעשו ברפידים, שאמרו היש ה' בקרבנו אם אין (שמות יז ז), הוא אומר להם זכור את אשר עשה לך עמלק.