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?
2
Answers
You error is clear which is the name of the
SecretID
andSecretId
. You named it incorrectly.Just change the variable name to
SecretId
instead ofSecretID
the last letter should be lowercase.But if you want here is the example how to use it
Here is working code to get a secret using Python.