Home > Software engineering >  Can we tag a lambda invocation for cost tracking purposes?
Can we tag a lambda invocation for cost tracking purposes?

Time:02-03

We have a multi app / tenant lambda

Are we able at runtime tag the current invocation with a specific tag ?

i.e. when called with specific token we know this is from APP X and user Y

Can we add 2 tags to the current invocation ?

App: X

User: Y

CodePudding user response:

AWS has a nice blog post on how to accomplish something like this. https://aws.amazon.com/blogs/mt/using-aws-x-ray-and-aws-application-cost-profiler-to-track-tenant-cost-of-shared-aws-infrastructure/

Distributed tracing with AWS X-Ray AWS X-Ray is a distributed tracing service helping developers analyze and debug distributed applications, such as those built via a microservices architecture. These trace summaries generated by AWS X-Ray contain information about services and resources used in the request. By instrumenting your existing application that is using AWS X-Ray with tenant information, tenant usage metadata can then be generated for services like AWS Lambda, Amazon DynamoDB, Amazon Simple Notification Service (SNS), and Amazon Simple Queue Service (SQS).

exports.handler = async (event, context) => {
            AWSXRay.captureFunc("annotations", function (subsegment) {
              subsegment.addAnnotation("Tenant_id", event.tenantId);
});
    }
  • Related