So, if I understood the question correctly
In $t=1$ you have $n_1$ amazon shares that are sold for $p_1$ each. You also have $C_1$ in cash, for a total portfolio value of
$$W_1 = n_1 p_1 + C_1 $$
In $t=2$ the price of the amazon shares rose to $p_2$. Now your portfolio value is
$$W_2 = n_1 p_2 + C_1 $$
You want a new situation
$$W_2^{'} = n_2 p_2 + C_2 $$
In which you have sold $n_1 - n_2$ Amazon shares, and put the proceedings of the selling in cash. You want to impose that the value of the Amazon shares over the total value of the portfolio is the same in $W_2^{'}$ and $W_1$
So you have 2 conditions:
(1) $$\dfrac{n_2 \cdot p_2}{W_2^{'}} = \dfrac{n_1 \cdot p_1}{W_1}$$
and (2)
$$C_2 = C_1 + p_2 (n_1 - n_2)$$
The second condition arises from the fact that the cash in $t=2$ is equal to the cash in $t=1$ plus the proceedings of the shares you sold. You do not add additional cash from your pockets.
Putting (2) in (1) and solving for $n_2$ yields to:
$$n_2 = n_1 \cdot \dfrac{p_1}{p_2} \cdot \dfrac{C_1 + n_1 p_2}{C_1 + n_1 p_1}$$
Suppose $p_1 = 1\$$,$p_2 = 2\$$,$n_1 = 1 \,\text{share}$, $C_1 = 1\$$, the formula yields $ n_2 = 0.75 \,\text{shares}$.
In fact, both the initial weight of the Amazon share is 50%.
Also the final weight of the Amazon shares, after the price doubled and you sold 0.25 shares, is 50%.
EDIT:
The amount of shares you have to sell is
$$ n_1 - n_2 = \Delta n = n_1 \left[ \dfrac{C_1 (p_2 - p_1)}{p_2(C_1 +n_1 p_1)} \right]$$
Hypothesizing that the price double ($p_2 = 2 p_1$) and the initial cash weight for 50% ($C_1 = n_1 p_1$), we obtain
$$ \dfrac{\Delta n}{n_1} = \dfrac{1}{4} $$
That is, you have to sell 25% of your Amazon shares.
EDIT2:
There is the implicit assumption that you are able to sell all your $\Delta n$ shares for the same price of $p_2$. This may not be true, especially if you have to sell a large amount of shares.
You may not be able to find people willing to buy later shares at $p_2$, because they entered a buy order for a lower price
Moreover, if the price falls ($p_2 < p_1$), you need to buy shares. In this case, if you don't want to borrow money, you have to impose the restriction $C_2 \ge 0$, which leads to a minimum $p_2$ value. If the price falls below this value, you have lost all your cash and you are not able to buy further shares.