'AWS SDK NodeJS Send a Metric Search

I am trying to use AWS NodeJs SDK to send a Metric search, I can't find any clear resources for this. I know I have to use the GetMetric API. I want to be able to get the results of the below metric search query:

SUM(SEARCH('Namespace="appName" MetricName="http.server.requests.count" (status="2xx" OR status="4xx") uri="uri"', 'Sum', 300))

Code I have so far:

async () => {
        const data = await cloudWatchClient.send(
            new GetMetricDataCommand(
                {
                    StartTime: startTime,
                    EndTime: endTime,
                    MetricDataQueries: [
                       {
                           Id: "queryA",
                            Expression:
                            `SUM(SEARCH('Namespace="${appName}" MetricName="http.server.requests.count" (status="2xx" OR status="4xx") uri="${uri}"', 'Sum', 300))`
                        }
                    ]
            })

        );

I have cloudWatchClient configured and also have cloudwatch:GetMetricData and cloudwatch:ListMetrics policies. The above code doesn't return any data or error.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source