Skip to content

Instantly share code, notes, and snippets.

@rrobby86
Created April 7, 2021 10:13
Show Gist options
  • Select an option

  • Save rrobby86/9c1935b4d2d6f7ca496ebfda95b65a73 to your computer and use it in GitHub Desktop.

Select an option

Save rrobby86/9c1935b4d2d6f7ca496ebfda95b65a73 to your computer and use it in GitHub Desktop.
Simple CLI for AWS SageMaker notebook instances
#!/bin/bash
# TODO:
# - start, stop, status commands
# - jupyterlab option
# - pass settings (e.g. profile) to aws cli
PROGNAME=$(basename $0)
AWS="aws"
OPEN="xdg-open"
cmd_help() {
echo "Usage: $PROGNAME <command> [args]\n"
cat <<EOF
Subcommands:
list
open <instance>
EOF
}
cmd_list() {
$AWS sagemaker list-notebook-instances --query 'NotebookInstances[*].[NotebookInstanceName]' --output text
}
cmd_open() {
$OPEN $($AWS sagemaker create-presigned-notebook-instance-url --notebook-instance-name $1 --query AuthorizedUrl --output text)
}
subcmd=$1
case $subcmd in
"" | "-h" | "--help")
cmd_help
;;
*)
shift
cmd_${subcmd} $@
if [ $? = 127 ]; then
echo "Unrecognized subcommand, run '$PROGNAME --help' to list subcommands"
exit 1
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment