I need to extract the AWS Sagemaker Space (collaborative option of Sagemaker Studio) username. It's presented in top right corner of the picture below. There is a similar question here but it is for Personal Studio instance and the user element does not exist in /opt/ml/metadata/resource-metadata.json in case of Sagemaker Space. I can get it via JS magics, but I have an issue getting the variable from JS side to notebook. Any ideas where/how to get this username (I would expect it in JUPYTER_USER env, but nothing like this is presented). Thanks!
%%javascript
alert(document.getElementById('space-menu').getElementsByTagName("p")[0].innerHTML.split('/')[0].trim())
but if I try to pass variable from JS to notebook I get Javascript Error: IPython is not defined
%%javascript
IPython.notebook.kernel.execute('foo=bar')