python-3.x get_execution_role()脚本生成器:未知服务错误:未知服务:'sagemaker-metrics',有效的服务名称为:存取分析器

ntjbwcob  于 2023-01-10  发布在  Python
关注(0)|答案(1)|浏览(71)

我正在尝试这段代码,以获得iam角色编程。

from sagemaker import get_execution_role
get_execution_role()

它给出以下错误。

---------------------------------------------------------------------------
UnknownServiceError                       Traceback (most recent call last)
/tmp/ipykernel_8241/4227035378.py in <cell line: 1>()
----> 1 get_execution_role()
      2 role="arn:aws:iam::984132841759:role/service-role/AmazonSageMaker-ExecutionRole-20221129T111507",

~/anaconda3/envs/tensorflow2_p38/lib/python3.8/site-packages/sagemaker/session.py in get_execution_role(sagemaker_session)
   5039     """
   5040     if not sagemaker_session:
-> 5041         sagemaker_session = Session()
   5042     arn = sagemaker_session.get_caller_identity_arn()
   5043 

~/anaconda3/envs/tensorflow2_p38/lib/python3.8/site-packages/sagemaker/session.py in __init__(self, boto_session, sagemaker_client, sagemaker_runtime_client, sagemaker_featurestore_runtime_client, default_bucket, settings, sagemaker_metrics_client)
    131         self.settings = settings
    132 
--> 133         self._initialize(
    134             boto_session=boto_session,
    135             sagemaker_client=sagemaker_client,

~/anaconda3/envs/tensorflow2_p38/lib/python3.8/site-packages/sagemaker/session.py in _initialize(self, boto_session, sagemaker_client, sagemaker_runtime_client, sagemaker_featurestore_runtime_client, sagemaker_metrics_client)
    183             self.sagemaker_metrics_client = sagemaker_metrics_client
    184         else:
--> 185             self.sagemaker_metrics_client = self.boto_session.client("sagemaker-metrics")
    186         prepend_user_agent(self.sagemaker_metrics_client)
    187 

~/anaconda3/envs/tensorflow2_p38/lib/python3.8/site-packages/boto3/session.py in client(self, service_name, region_name, api_version, use_ssl, verify, endpoint_url, aws_access_key_id, aws_secret_access_key, aws_session_token, config)
    297 
    298         """
--> 299         return self._session.create_client(
    300             service_name,
    301             region_name=region_name,

~/anaconda3/envs/tensorflow2_p38/lib/python3.8/site-packages/botocore/session.py in create_client(self, service_name, region_name, api_version, use_ssl, verify, endpoint_url, aws_access_key_id, aws_secret_access_key, aws_session_token, config)
    868             * path/to/cert/bundle.pem - A filename of the CA cert bundle to
    869               uses.  You can specify this argument if you want to use a
--> 870               different CA cert bundle than the one used by botocore.
    871 
    872         :type endpoint_url: string

~/anaconda3/envs/tensorflow2_p38/lib/python3.8/site-packages/botocore/client.py in create_client(self, service_name, region_name, is_secure, endpoint_url, verify, credentials, scoped_config, api_version, client_config)
     85         loader,
     86         endpoint_resolver,
---> 87         user_agent,
     88         event_emitter,
     89         retry_handler_factory,

~/anaconda3/envs/tensorflow2_p38/lib/python3.8/site-packages/botocore/client.py in _load_service_model(self, service_name, api_version)
    152                 'signatureVersion'
    153             ),
--> 154         )
    155         client_args = self._get_client_args(
    156             service_model,

~/anaconda3/envs/tensorflow2_p38/lib/python3.8/site-packages/botocore/loaders.py in _wrapper(self, *args, **kwargs)
    130     for this to be used, it must be used on methods on an
    131     instance, and that instance *must* provide a
--> 132     ``self._cache`` dictionary.
    133 
    134     """

~/anaconda3/envs/tensorflow2_p38/lib/python3.8/site-packages/botocore/loaders.py in load_service_model(self, service_name, type_name, api_version)
    375     def load_service_model(self, service_name, type_name, api_version=None):
    376         """Load a botocore service model
--> 377 
    378         This is the main method for loading botocore models (e.g. a service
    379         model, pagination configs, waiter configs, etc.).

UnknownServiceError: Unknown service: 'sagemaker-metrics'. Valid service names are: accessanalyzer, account, acm, acm-pca, alexaforbusiness, amp, amplify, amplifybackend, amplifyuibuilder, apigateway, apigatewaymanagementapi, apigatewayv2, appconfig, appconfigdata, appflow, appintegrations, application-autoscaling, application-insights, applicationcostprofiler, appmesh, apprunner, appstream, appsync, athena, auditmanager, autoscaling, autoscaling-plans, backup, backup-gateway, batch, braket, budgets, ce, chime, chime-sdk-identity, chime-sdk-meetings, chime-sdk-messaging, cloud9, cloudcontrol, clouddirectory, cloudformation, cloudfront, cloudhsm, cloudhsmv2, cloudsearch, cloudsearchdomain, cloudtrail, cloudwatch, codeartifact, codebuild, codecommit, codedeploy, codeguru-reviewer, codeguruprofiler, codepipeline, codestar, codestar-connections, codestar-notifications, cognito-identity, cognito-idp, cognito-sync, comprehend, comprehendmedical, compute-optimizer, config, connect, connect-contact-lens, connectparticipant, cur, customer-profiles, databrew, dataexchange, datapipeline, datasync, dax, detective, devicefarm, devops-guru, directconnect, discovery, dlm, dms, docdb, drs, ds, dynamodb, dynamodbstreams, ebs, ec2, ec2-instance-connect, ecr, ecr-public, ecs, efs, eks, elastic-inference, elasticache, elasticbeanstalk, elastictranscoder, elb, elbv2, emr, emr-containers, es, events, evidently, finspace, finspace-data, firehose, fis

我尝试了多种解决方案,从互联网上,如升级sagemaker和boto3到最新版本,没有运气。
我在sagemaker笔记本中使用conda_tensorflow2_py38内核。
任何帮助高度赞赏。提前感谢。

slwdgvem

slwdgvem1#

通过运行-%pip install --upgrade boto3来升级笔记本中的boto 3安装,升级完成后,重新启动内核并运行上面的单元格,它应该可以正常工作。
get_execution_role()函数正在寻找SageMaker会话,如果不存在,则创建一个,并且在sagemaker SDK的较新版本中,它也尝试为sagemaker-metrics创建一个客户端,这在较旧的boto 3版本中是不支持的。

相关问题