All posts
lambdaawscostobservability

Monitoring Lambda Costs: A Practical Dashboard

Quang Tran D.'s avatarQuang Tran D.

Lambda pricing is based on request count and GB-seconds, which can be tricky to attribute to specific functions or features. This article shows how to build a CloudWatch dashboard that breaks down Lambda costs by function, by stage, and by feature flag. We use CloudWatch Lambda Insights, custom metrics via EMF, and Cost Explorer exports. The article includes CloudFormation templates for the dashboard and a Node.js helper for emitting cost-attribution metrics from your handler code

/**
 * Standard AWS Lambda handler for Node.js.
 */
export const handler = async (event, context) => {
    // 1. Log incoming trigger data
    console.log("Received event:", JSON.stringify(event, null, 2));
    
    // 2. Extract values safely
    const name = event.name || "World";
    
    // 3. Formulate the response object
    const responseBody = {
        message: `Hello, ${name}!`,
        status: "success"
    };
    
    return {
        statusCode: 200,
        headers: {
            "Content-Type": "application/json"
        },
        body: JSON.stringify(responseBody)
    };
};