This AWS CDK construct export the default metrics created by the App Runner Service, you can use them to create dashboards or alarms.
Requirements To use this construct, you'll need the following:
- An AWS account with the necessary permissions to create AWS AppRunner and AWS CloudFormation resources.
- AWS CDK v2 installed and configured on your development machine.
- Node.js and TypeScript installed on your development machine.
To get started with this library, follow these steps:
- Install the library in your AWS CDK project by running the following command:
npm install cdk-apprunner-metrics
or, with yarn:
yarn add cdk-apprunner-metrics
- Import it in your CDK stack:
import { AppRunnerMetrics } from "cdk-apprunner-metrics";
- Instantiate the CfnService construct in your AWS CDK stack and provide the required parameters:
const service = new apprunner.CfnService(this, "AppRunnerService", {
serviceName: id,
/** Other config... **/
});
- Get the metric you desire:
const http2xxCountMetric = AppRunnerMetrics.http2xxResponseCount(service);
const http4xxCountMetric = AppRunnerMetrics.http4xxResponseCount(service);
const http5xxCountMetric = AppRunnerMetrics.http5xxResponseCount(service);
const requestLatencyMetric = AppRunnerMetrics.requestLatency(service);
const activeInstancesMetric = AppRunnerMetrics.activeInstances(service);
const cpuUtilizationMetric = AppRunnerMetrics.cpuUtilization(service);
const memoryUtilizationMetric = AppRunnerMetrics.memoryUtilization(service);
const concurrencyMetric = AppRunnerMetrics.concurrency(service);
-
You can use your metrics on whatever place you like.
-
You can also reference log groups for set up alarms if you like:
const svcLogGroup = AppRunnerMetrics.serviceLogGroup(this, `ServiceLogGroup`, service);
const appLogGroup = AppRunnerMetrics.applicationLogGroup(this, `AppLogGroup`, service);