Custom Docker Image throws an Error "Unable to determine execution role. Please provide via the --role argument,Must setup local AWS configuration with a region supported by SageMaker."

0

I am currently running a ML pipeline by using the Sagemaker SDKs.After training, I am trying to build a custom docker image by using processing step and consume that image in deploy step to create an endpoint for my model. Docker file contains an inference file. I am using sm-docker build and push docker image into ECR.

Note: Docker build did not work inside the studio.

Below is the code i am using

 build_processor = SKLearnProcessor(
    framework_version="0.23-1",
    role=role,
    instance_type="ml.m5.large",
    instance_count=1,
    base_job_name="docker-build-step",
)
 step_build_docker = ProcessingStep(
        name="BuildDockerImage",
        processor=build_processor,
        # depends_on=[step_train],
        inputs=[
            ProcessingInput(source="/root/test/pipelines/data/build", destination="/opt/ml/processing/dockerfile"),
   
        ], 
        outputs=[
            ProcessingOutput(output_name="docker_build_output", source="/opt/ml/processing/output"),
        ],
        
        # environment={
        # "AWS_REGION": region,
        # "AWS_EXECUTION_ROLE_ARN": role
       #  # },
       # arguments=[
       #  "--region", region,
       #  "--role", role
       #  ],
        code=os.path.join(BASE_DIR, "build_docker.py"),
    )

%%%docker_build.py
`def build_docker_image(image_repo,image_tag,new_directory):
   
    os.chdir(new_directory)

    docker_image_name = image_repo
    
    
    docker_tag =image_tag
    
    return subprocess.run(['sm-docker', 'build', '.', f'{docker_image_name}:{docker_tag}'], check=True)   `
   

`if __name__ == "__main__":
   
    # parser = argparse.ArgumentParser()
    # parser.add_argument("--region", type=str, required=True)
    # parser.add_argument("--role", type=str, required=True)
    # # Add other command-line arguments as needed
    # args,_ = parser.parse_known_args()
    # region=args.region
    # role=args.role
    # aws_region = os.environ.get("AWS_REGION")


    base_directory = "/opt/ml/processing/dockerfile"
    pathlib.Path(f"{base_directory}").mkdir(parents=True, exist_ok=True)
   
    print("Current working directory:", base_directory)
    image_repo="sage"
    image_tag="sagemaker-studio-cluster-model-v1-2"

    build_result=build_docker_image(image_repo,image_tag,base_directory)
    if build_result.returncode == 0:
        logging.info("Docker image build succeeded!")
    else:
        logging.error("Docker image build failed!")`

The issue i am facing is that the IAM role is not being passed into build_docker.py file, although I am explicitly declaring via sklearn processor role parameter.

** Couple of things i tried which did not work **

  • I tried passing the IAM role and region via environment variables and that did not work.
  • I also tried to create a config file as per the below documentation and passed the role from config.yaml.
  • https://docs.aws.amazon.com/sagemaker/latest/dg/train-remote-decorator-config.html
  • the file was loaded successfully but did not assign the role from config file.
  • Manually tried passing the role in the docker_build script by using the get_execution_role function.That did not work either.

Could you please let know how to resolve this error?

Error logs

Traceback (most recent call last): File "/miniconda3/lib/python3.7/site-packages/sagemaker_studio_image_build/cli.py", line 50, in get_role return "/".join(sagemaker.get_execution_role().split(":")[-1].split("/")[1:]) File "/miniconda3/lib/python3.7/site-packages/sagemaker/session.py", line 4729, in get_execution_role sagemaker_session = Session() File "/miniconda3/lib/python3.7/site-packages/sagemaker/session.py", line 132, in init sagemaker_featurestore_runtime_client=sagemaker_featurestore_runtime_client, File "/miniconda3/lib/python3.7/site-packages/sagemaker/session.py", line 152, in _initialize "Must setup local AWS configuration with a region supported by SageMaker."

Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen