Search code examples
boto3amazon-cloudwatch

Boto3 TypeError: get_metric_data() only accepts keyword arguments - calling api with dynamic input


I have a function "get_metrics" that takes input which I want to build dynamically and pass it as parameter to function. But when call function with input I get error below. If I paste input directly in call it works.

raise TypeError( TypeError: get_metric_data() only accepts keyword arguments.

def get_metrics(metrics_input):
    client = boto3.client(service_name='dms', region_name='us-east-1')
    response = client.get_metric_data(metrics_input)
    return response

metrics_input = This is built dunamically result = get_metrics(metrics_input)

I tried directly adding generated input in api call and it works but does not work if passing as parameter to function.


Solution

  • I was able to solve this using json.loads(metrics_input) before passing it to function.