4

In the GitHub repo for my AWS SageMaker project, commits are labelled as being created by the user "EC2 Default User".

enter image description here

How do I customize the name of this user in SageMaker so that it is used every time I start my Notebook Instance?

orome
  • 45,163
  • 57
  • 202
  • 418
  • Possible duplicate of [How to change user identity when git pushing via ssh?](https://stackoverflow.com/questions/39064276/how-to-change-user-identity-when-git-pushing-via-ssh) – Code-Apprentice Dec 18 '18 at 00:14
  • 1
    Not a dupe. This is specifically how to do that in the context of the SageMaker workflow. – orome Dec 18 '18 at 00:18

3 Answers3

10

To systematically fix this issue you can use Start notebook configuration in Lifecycle configurations.
Here is the script template:

#!/bin/bash

set -e
cat << EOF >> /home/ec2-user/.gitconfig
[user]
        name = John Doe
        email = johndoe@example.com
EOF

Please, replace name and email with your actual values.

This script will append lines to .gitconfig file for ec2-user on SageMaker's machine. That's the same effect you can manually achieve with following 2 commands:

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Because of SageMaker's Notebook Instances start/stop policy:

Only files and data saved within the /home/ec2-user/SageMaker folder persist between notebook instance sessions. Files and data that are saved outside this directory are overwritten when the notebook instance stops and restarts.

you need to add this as Start notebook script, so it will be run every time Notebook Instance is started.

Here is a screenshot how it looks like from AWS Web Console:
Start script config example

Taras Slipets
  • 136
  • 1
  • 9
  • Hi thanks for this, I followed the steps you mentioned in the answer and tried on my notebook, i managed to commit with the desired username, but the commit isn't signed (I'm expecting there's a `verified` icon next to my commit in GitHub), I have signed commit setup with GPG on my local machine, but do you know how to set this up in SageMaker lifecycle configuration? – wawawa May 31 '23 at 08:12
3

Are you pushing from an ec2 instance?

The commit author has nothing to do with which ssh key is used to authenticate the push.

It has to do with the current Git config:

git config user.name
git config user.email

Make sure the values for those local settings are correct (local for the EC2 Git repo), and the next new commits will be with the right author.

I copied and give credit to this post: How to change user identity when git pushing via ssh?

ByungWook
  • 374
  • 1
  • 4
  • SageMaker is doing all the pushes via Jupyter Lab’s gut extension. So the question is, I guess, how that is configured? – orome Dec 18 '18 at 00:17
  • 1
    SageMaker doesn't configure the user.name and user.email on the Notebook Instance so it's ```EC2 Default User``` by default. If you want to configure the name and email you can run the above command @ByungWool mentioned. You can also add this script to a Lifecycle Config so it will be configured automatically every time you start the Notebook Instance. – Han Dec 18 '18 at 00:36
  • @Han: That's the answer. But this answer is just the given background for it. – orome Dec 19 '18 at 17:37
  • @Han: Actually, attempting `git config user.name "SOME NAME"` causes Notebook start to fail. – orome Dec 19 '18 at 18:11
  • @Han Is there a way to configure these settings based on who is signed in to the notebook? – rump roast Feb 07 '19 at 19:52
  • is there a way to setup signed commit within lifecycle configuration scripts? – wawawa May 31 '23 at 08:50
-1

You can also use the built-in Git integration of the SageMaker notebooks to define the user name (and provide the password for it).

Here is a link to a guide: https://aws.amazon.com/blogs/machine-learning/amazon-sagemaker-notebooks-now-support-git-integration-for-increased-persistence-collaboration-and-reproducibility/

enter image description here

Guy
  • 12,388
  • 3
  • 45
  • 67