aws lex : how much RecognizeText are requested ?

0

I am trying to calculate how much lex costs.

i found RecognizeText reqeusts that i request are saved in AWS.

i am gonna use it to calculate costs. ( 0.00075$ per RecognizeText )

what i am asking are two things.

  1. how can i get the number of how much RecognizeText i have requested ?

  2. is there other way to get how much costs for each bot ?

i am using AWS JavaScript SDK. just consider it for me.

thanks!

Jeon
질문됨 한 달 전131회 조회
1개 답변
0

Here's a general outline of how you can achieve this using the AWS JavaScript SDK:

Enable CloudWatch Metrics: Ensure that CloudWatch metrics are enabled for your Amazon Lex bot. You can enable this option in the Amazon Lex console or via the AWS CLI. https://docs.aws.amazon.com/lex/latest/dg/gs-cli.html

Retrieve Metrics Data: Use the getMetricData method from the AWS CloudWatch SDK to retrieve metric data for your Amazon Lex bot. You'll need to specify the Namespace, MetricName, Dimensions, and StartTime and EndTime parameters to filter the metric data appropriately.

Calculate Total Cost: Once you have retrieved the number of RecognizeText requests, you can calculate the total cost by multiplying the number of requests by the cost per request (0.00075$ per RecognizeText).

example of how you can achieve this using the AWS JavaScript SDK

const AWS = require('aws-sdk');

// Configure AWS credentials
AWS.config.update({ region: 'your-region', accessKeyId: 'your-access-key', secretAccessKey: 'your-secret-key' });

// Create CloudWatch service object
const cloudwatch = new AWS.CloudWatch();

// Define parameters for GetMetricData API operation
const params = {
  MetricDataQueries: [
    {
      Id: 'm1',
      MetricStat: {
        Metric: {
          Namespace: 'AWS/Lex',
          MetricName: 'BilledTextSentCount',
          Dimensions: [
            {
              Name: 'BotName',
              Value: 'your-bot-name'
            },
            {
              Name: 'BotAlias',
              Value: 'your-bot-alias'
            }
          ]
        },
        Period: 3600, // One hour
        Stat: 'Sum'
      }
    }
  ],
  StartTime: new Date(Date.now() - 3600000), // One hour ago
  EndTime: new Date(),
  ScanBy: 'TimestampDescending'
};

// Retrieve metric data
cloudwatch.getMetricData(params, function(err, data) {
  if (err) {
    console.log('Error', err);
  } else {
    const metricData = data.MetricDataResults[0];
    const sum = metricData.Values[0];
    const totalRequests = sum.Value;
    const costPerRequest = 0.00075;
    const totalCost = totalRequests * costPerRequest;

    console.log('Total RecognizeText requests:', totalRequests);
    console.log('Total cost:', totalCost.toFixed(2), '$');
  }
});

Replace 'your-region', 'your-access-key', 'your-secret-key', 'your-bot-name', and 'your-bot-alias' with your actual AWS region, access key, secret key, bot name, and bot alias respectively.

profile picture
전문가
답변함 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠