1

Hi I am trying to retrieve secrets using python SDK which will retrieve the secret name called test in the specified region's AWS secrets manager and getting the below error while running a simple python script:

#!/usr/bin/env python import boto3 import base64 from botocore.exceptions import ClientError def get_secret(): secret_name = "test" region_name = "tesdas" print("inside rds secrete") # Create a Secrets Manager client session = boto3.session.Session() client = session.client( service_name='secretsmanager', region_name=region_name ) # In this sample we only handle the specific exceptions for the 'GetSecretValue' API. # See https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html # We rethrow the exception by default. try: get_secret_value_response = client.get_secret_value( SecretId=secret_name ) # Decrypts secret using the associated KMS CMK. # Depending on whether the secret is a string or binary, one of these fields will be populated. if 'SecretString' in get_secret_value_response: secret = get_secret_value_response['SecretString'] print("RDS Secret") print(secret) else: decoded_binary_secret = base64.b64decode(get_secret_value_response['SecretBinary']) get_secret() 

Below is the error which I am getting, while executing the script:

Traceback (most recent call last): File "test.py", line 60, in <module> get_secret() File "test.py", line 18, in get_secret region_name=region_name File "/usr/lib/python2.7/site-packages/boto3/session.py", line 263, in client aws_session_token=aws_session_token, config=config) File "/usr/lib/python2.7/site-packages/botocore/session.py", line 836, in create_client client_config=config, api_version=api_version) File "/usr/lib/python2.7/site-packages/botocore/client.py", line 64, in create_client service_model = self._load_service_model(service_name, api_version) File "/usr/lib/python2.7/site-packages/botocore/client.py", line 97, in _load_service_model api_version=api_version) File "/usr/lib/python2.7/site-packages/botocore/loaders.py", line 132, in _wrapper data = func(self, *args, **kwargs) File "/usr/lib/python2.7/site-packages/botocore/loaders.py", line 378, in load_service_model known_service_names=', '.join(sorted(known_services))) botocore.exceptions.UnknownServiceError: Unknown service: 'secretsmanager'. Valid service names are: acm, apigateway, application-autoscaling, appstream, athena, autoscaling, batch, budgets, clouddirectory, cloudformation, cloudfront, cloudhsm, cloudsearch, cloudsearchdomain, cloudtrail, cloudwatch, codebuild, codecommit, codedeploy, codepipeline, codestar, cognito-identity, cognito-idp, cognito-sync, config, cur, datapipeline, dax, devicefarm, directconnect, discovery, dms, ds, dynamodb, dynamodbstreams, ec2, ecr, ecs, efs, elasticache, elasticbeanstalk, elastictranscoder, elb, elbv2, emr, es, events, firehose, gamelift, glacier, greengrass, health, iam, importexport, inspector, iot, iot-data, kinesis, kinesisanalytics, kms, lambda, lex-models, lex-runtime, lightsail, logs, machinelearning, marketplace-entitlement, marketplacecommerceanalytics, meteringmarketplace, mturk, opsworks, opsworkscm, organizations, pinpoint, polly, rds, redshift, rekognition, resourcegroupstaggingapi, route53, route53domains, s3, sdb, servicecatalog, ses, shield, sms, snowball, sns, sqs, ssm, stepfunctions, storagegateway, sts, support, swf, waf, waf-regional, workdocs, workspaces, xray 
2
  • 1
    Check with Python 3+ Commented Jul 29, 2020 at 9:56
  • 1
    Are you passing the proper region. Mostly this error will occur for wrong region only. Commented Jul 29, 2020 at 19:03

1 Answer 1

1

It looks like @Narsireddy is correct. The line region_name = "tesdas" does not specify a valid region. The region should look something like "us-east-1" or "us-west-2".

Sign up to request clarification or add additional context in comments.

1 Comment

Yes I am passing the correct region the problem is with lower version of boto3, i Have asked to install higher version of python(3) and boto3 relevant to it. In our current organisation, there is a restriction to install pip3 to install boto3. As of now , I am trying to sue botocore to extract the secrets from secrets manager

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.