I am using a simple boto3 script to retrieve a parameter from SSM param store in my aws account. The python script looks like below:
client = get_boto3_client('ssm', 'us-east-1')
try:
response = client.get_parameter(Name='my_param_name',WithDecryption=True)
except Exception as e:
logging.error("retrieve param error: {0}".format(e))
raise e
return response
If the given parameter is not available, I get a generic error in the response like below:
An error occurred (ParameterNotFound) when calling the GetParameter operation: Parameter my_param_name not found.
I have verified method signature from boto3 ssm docs. Related AWS API Docs confirms to return a 400 response when parameter does not exist in the param store.
My question is that how do I verify if the exception caught in the response is actually a 400 status code so that I can handle it accordingly.