The Fama-MacBeth method estimates the market price of factor risk (MPR) $\lambda$ and the amount of risk exposure. There are several ways to define the $\lambda$
$$ E[r_i] - r_f = \lambda \times\beta_i\quad \forall i \in \{1, ..., I\} $$
Step 1: Choose an economic theory that supports the factor model (assumed to be CAPM here)
Step 2: Collect a panel of asset excess returns $\{r_{i,t}\}{i=1,t=1}^{i=I,t=T}$ and a time-series of the risk factor. For the CAPM that would be: $\{r{M,t}-r_{f,t}\}_{t=1}^{t=T}$
Step 3: Perform a time-series regression to get each asset's beta (input: asset excess returns $r_{i,t}$ , output: $\hat{\beta_i}$):
$$ \text{for all stocks} \; i \in \{1,...,I\} \; \text{run the following time-series regression:} \\ \underbrace{ \begin{pmatrix} r_{i,t=1} \\ .... \\ r_{i,t=T} \end{pmatrix}}{T \times 1} = \underbrace{\begin{pmatrix} 1 & (r{M,t=1}-r_{f,t=0}) \\ ... & ... \\ 1 & (r_{M,t=T}-r_{f,t=T-1}) \end{pmatrix}}{T \times 2} \begin{pmatrix} \beta{i,0} \\ \beta_{i,1} \end{pmatrix} + \begin{pmatrix} \epsilon_{i,t=1} \\ ... \\ \epsilon_{i,t=T} \end{pmatrix} $$
to recover $\{\hat{\beta_i}\}_{i=1}^{I}$ (btw this a set of I vectors and each vector has two components). If the data supports OLS assumptions (OLS), you can rely on OLS estimates, otherwise use GLS (Generalized Least Squares).
Step 4: Treat $\{\hat{\beta_i}\}_{i=1}^{I}$ as observed and run for each time period as a cross-sectional regression (input: $\hat{\beta_i}$, output: $\hat\alpha, \hat\lambda$):
$$ \text{for all} \; t \in \{1,...,T\} \; \text{run the following cross-sectional regression:} \\ \begin{pmatrix} r_{i=1,t} \\ .... \\ r_{i=I,t} \end{pmatrix} = \begin{pmatrix} 1 & \hat{\beta}{i=1,1} \\ ... & ... \\ 1 & \hat{\beta}{i=I,1} \end{pmatrix} \begin{pmatrix} \alpha_{t} \\ \lambda_{t} \end{pmatrix} + \begin{pmatrix} e_{i=1,t} \\ ... \\ e_{i=I,t} \end{pmatrix} \\
$$
which allows you to get a least-squares estimate for
$$ [ \hat{\alpha}{t=1}, \, , ..., \, \hat{\alpha}{t=T} ] \quad \quad \text{and} \quad [ \hat{\lambda}{t=1}, \, ... , \, \hat{\lambda}{t=T} ] $$
Step 5: Fama-MacBeth define the risk premium for market exposure (factor premium for a unit of exposure to market risk, $E[r_M] - r_f$ ) as the mean of the $\hat\lambda$
$$ \hat{\lambda}{\text{FMacB}} := \frac{1}{T} \sum{t=1}^T \hat{\lambda}_{t} $$
Step 6: Test whether $\hat{\lambda}_{\text{FMacB}}$ is statistically different from zero via t-statistic
$$ t_{\lambda} := \frac{\hat{\lambda}_{\text{FMacB}}}{ std(\hat{\lambda_t}) / \sqrt{T}} $$
where $std(\hat{\lambda})$ is the sample standard deviation of the estimated $\{ \hat{\lambda}{t}\}^T{t=1}$