Git Webhook to trigger SageMaker Pipeline

20 views Asked by At

We are currently using a private hosted git repository (not connected in codecommit, github, bitbucket etc.) And inside the Sagemaker studio, I connected the git repository. How can I trigger a sagemaker pipeline once some code is pushed to the git repository? Is there a straightforward way (or any alternative way) on how to do this?

I tried using webhooks: post-receive and post update not working. I tried doing this in pre-commit webhook and it is running fine. but when tried on post-receive/update, it doesn't work.

# Pipeline Trigger
# Check if the last argument is '0' (indicating a successful push)
if [ "$1" = "0" ]; then
    log_message "Push to Git repository detected. Triggering SageMaker Studio pipeline..."

    # Trigger SageMaker Studio pipeline
    pipeline_execution_output=$(aws sagemaker start-pipeline-execution \
        --pipeline-name "$SAGEMAKER_PIPELINE_NAME" \
        2>&1)

    # Check if the pipeline execution was successful
    if [ $? -eq 0 ]; then
        log_message "SageMaker Studio pipeline execution triggered successfully."
    else
        log_message "Failed to trigger SageMaker Studio pipeline execution. Error: $pipeline_execution_output"
    fi
else
    # Log unsuccessful push
    log_message "Failed to push changes to the repository."
fi
1

There are 1 answers

0
Janosch Woschitz On

Per git documentation, post-receive and post-update hooks are executed on the remote server.

You'd need to validate if your remote server is able to run the AWS CLI command.

Alternatively, you could consider moving your repo to CodeCommit and using EventBridge to trigger the SageMaker Pipeline: https://docs.aws.amazon.com/codecommit/latest/userguide/monitoring-events.html