sagemaker-ssh-helper
sagemaker-ssh-helper copied to clipboard
sm-ssh-ide script failure on grep during init-ssm
Hello, firstly, thank you for the wonderful library!
We encountered a problem when initializing ssm in the case when the ExecutionRole is not available for the user-profile, but only for the domain.
The sm-ssh-ide script, fails due to the use of grep within a pipeline combined with set -o pipefail.
The grep command can exit with code 1 if "ExecutionRole" is not found, triggering the pipefail behavior and causing the script to terminate.
Steps to Reproduce:
- Run the script in an environment where "ExecutionRole" is not present in the user_profile_json.
- Observe that the script fails due to grep exiting with code 1.
Suggested Solution:
- Temporarily disable
pipefailand re-enable after the condition is processed.
set +o pipefail
# execution_role extraction
set -o pipefail
- Add
|| true;
execution_role=$(echo "$user_profile_json" | {grep "ExecutionRole" || true;} \
| sed -e 's/^.*"ExecutionRole": \"\([^"]*\)\".*$/\1/')
# ...
execution_role=$(echo "$domain_json" | {grep "ExecutionRole" || true;} \
| sed -e 's/^.*"ExecutionRole": \"\([^"]*\)\".*$/\1/')
Hi, @hidemire , thank you for pointing to this bug and to the solutions! I've applied the second solution to the main branch and it will appear in the next release.
Released in v2.2.1