The match will be played in Poznań, western Poland, on July 5 or 6, and the second leg will take place a week later in Azerbaijan, Polish state news agency PAP has reported.
The winner of the two matches will go on to face Swiss side FC Zürich in the second round of Champions League qualifiers.
The loser will be relegated to the lower Europa League.
To qualify for the Champions League group stage, Lech Poznań need to eliminate Qarabag Agdam, FC Zürich and two other rivals, the PAP news agency reported.
Lech in May won the Polish premier league championship for the eighth time.
Source: TVP Sport, PAP