Okay, I found what was an issue. The problem was I previously created this component but with a different environment. And because the environment field is not mutable when I tried to update the old one I got this kind of error (for me it's a little bit confusing but OK). However, if someone will have the same issue how to correctly link your environment inside the yml file here is the correct version:
name: my_component
display_name: Run test code
version: 1
type: command
inputs:
data_path:
type: uri_folder
code: .
environment: azureml:aml-my-custom-env@1
command: >-
python test_code.py
--data_path ${{inputs.data_path}}