Search code examples
amazon-web-servicesaws-lambdaboto3aws-secrets-manager

AWS Secret Manager `ParamValidationError`: `"SecretID", must be one of: SecretId, VersionId, VersionStage`


I am having a problem with accessing a secret from Secret Manager in a lambda function.

Here is the relevant code:

import boto3

session = boto3.session.Session()
secretsmanager = session.client(service_name="secretsmanager")

get_secret_value_response = secretsmanager.get_secret_value(
    SecretID="arn:aws:secretsmanager:SECRETNAME"
)
secret = get_secret_value_response["SecretString"]

The error message, however, is confusing. Neither I found mentions of it elsewhere.

[ERROR] ParamValidationError: Parameter validation failed:
Missing required parameter in input: "SecretId"
Unknown parameter in input: "SecretID", must be one of: SecretId, VersionId, VersionStage
Traceback (most recent call last):
  File "/var/task/notification_parser.py", line 14, in handler
    get_secret_value_response = secretsmanager.get_secret_value(
  File "/var/runtime/botocore/client.py", line 530, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/var/runtime/botocore/client.py", line 919, in _make_api_call
    request_dict = self._convert_to_request_dict(
  File "/var/runtime/botocore/client.py", line 990, in _convert_to_request_dict
    request_dict = self._serializer.serialize_to_request(
  File "/var/runtime/botocore/validate.py", line 381, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())

The documentation shows a string value, so I am confused.

Any ideas where I could go wrong?


Solution

  • You error is clear which is the name of the SecretID and SecretId. You named it incorrectly.

    Just change the variable name to SecretId instead of SecretID the last letter should be lowercase.

    But if you want here is the example how to use it

    import boto3
    
    
    SECRET_ARN = "YOUR_SECRET_ARN"
    secret_manager = boto3.client('secretsmanager')
    
    response = secret_manager.get_secret_value(
        SecretId=SECRET_ARN
    )
    
    # this might be a json string so you might need to parse it
    # to parse it you can use json.loads(response['SecretString'])
    print('Secret: ' + response['SecretString'])