Earned Income and Roth IRA

I had a small amount of earned income in 2022, approximately $3,000.

Can I put that amount into my Roth IRA?

Do I need to put it into my Roth IRA in the year it was earned (2022), or is it okay to add it now in the year 2023?