Skip to content

Ability to expose additional ports from the container in Local mode #2729

@koduruprasanth

Description

@koduruprasanth

Describe the feature you'd like
Ability to expose additional ports from the container in Local mode.

How would this feature be used? Please describe.
Exposing debug ports from within the container would allow developers to attach remote debuggers to the code running in local Sagemaker containers. This would help accelerate development of the scripts running within the Sagemaker container for all supported local use cases.

Here is an example of how to debug scripts running in the container using PyCharm.

VSCode recommends using debugpy in order to support remote debugging. I was able to setup a sample script that waits for the remote debugger to attach using the following code.

import subprocess
import debugpy

debugpy.listen('0.0.0.0', 4200)
print("Waiting for client to attach...")
debugpy.wait_for_client()

input_data_path = 'opt/ml/processing/input_data'
processed_data_path = '/opt/ml/processing/processed_data'

def main():
    print("Processing Started")
    result = subprocess.run(['find', f"{input_data_path}"], stdout=subprocess.PIPE)
    print(result.stdout)
    print("Processing Completed")

if __name__ == '__main__':
    main()
Job Name:  sklearn-2021-10-25-19-57-00-565
Inputs:  [{'InputName': 'input-1', 'AppManaged': False, 'S3Input': {'S3Uri': 's3://sagemaker-us-east-1-XXXXXXXX/sklearn-2021-10-25-19-57-00-565/input/input-1', 'LocalPath': '/opt/ml/processing/input_data/', 'S3DataType': 'S3Prefix', 'S3InputMode': 'File', 'S3DataDistributionType': 'FullyReplicated', 'S3CompressionType': 'None'}}, {'InputName': 'code', 'AppManaged': False, 'S3Input': {'S3Uri': 's3://sagemaker-us-east-1-XXXXXXXX/sklearn-2021-10-25-19-57-00-565/source/sourcedir.tar.gz', 'LocalPath': '/opt/ml/processing/input/code/', 'S3DataType': 'S3Prefix', 'S3InputMode': 'File', 'S3DataDistributionType': 'FullyReplicated', 'S3CompressionType': 'None'}}, {'InputName': 'entrypoint', 'AppManaged': False, 'S3Input': {'S3Uri': 's3://sagemaker-us-east-1-XXXXXXXX/sklearn-2021-10-25-19-57-00-565/source/runproc.sh', 'LocalPath': '/opt/ml/processing/input/entrypoint', 'S3DataType': 'S3Prefix', 'S3InputMode': 'File', 'S3DataDistributionType': 'FullyReplicated', 'S3CompressionType': 'None'}}]
Outputs:  [{'OutputName': 'word_count_data', 'AppManaged': False, 'S3Output': {'S3Uri': 's3://sagemaker-us-east-1-XXXXXXXX/sklearn-2021-10-25-19-57-00-565/output/word_count_data', 'LocalPath': '/opt/ml/processing/processed_data/', 'S3UploadMode': 'EndOfJob'}}]
Using the short-lived AWS credentials found in session. They might expire while running.
Creating se2bjup9vi-algo-1-3lqaj ... 
Creating se2bjup9vi-algo-1-3lqaj ... done
Attaching to se2bjup9vi-algo-1-3lqaj
se2bjup9vi-algo-1-3lqaj | Found existing installation: typing 3.7.4.3
se2bjup9vi-algo-1-3lqaj | Uninstalling typing-3.7.4.3:
se2bjup9vi-algo-1-3lqaj |   Successfully uninstalled typing-3.7.4.3
se2bjup9vi-algo-1-3lqaj | Collecting debugpy
se2bjup9vi-algo-1-3lqaj |   Downloading debugpy-1.5.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.9 MB)
     |████████████████████████████████| 1.9 MB 28.6 MB/s 
se2bjup9vi-algo-1-3lqaj | Installing collected packages: debugpy
se2bjup9vi-algo-1-3lqaj | Successfully installed debugpy-1.5.1
se2bjup9vi-algo-1-3lqaj | Waiting for client to attach...

However, I am not able to attach a remote debugger since this port is not exposed from the launched container. I am current not aware of a way to expose a port on the container launched by Sagemaker Local. I would like this feature to make it possible to expose additional ports through local session configuration.

Describe alternatives you've considered
As shown in the above linked example, it is possible to remote debug Sagemaker local scripts running in a container with PyCharm. However, it requires a paid subscription.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions