Skip to content

Commit

Permalink
feat: save function tags in auto trace
Browse files Browse the repository at this point in the history
  • Loading branch information
tschoffelen committed Sep 7, 2024
1 parent bfee4c4 commit 65c9578
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/api/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ provider:
- lambda:ListFunctions
- lambda:UpdateFunctionConfiguration
- lambda:GetLayerVersion
- lambda:ListTags
Resource:
- "*"
- Effect: Allow
Expand Down
20 changes: 20 additions & 0 deletions packages/api/src/events/auto-trace.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
LambdaClient,
ListFunctionsCommand,
ListTagsCommand,
UpdateFunctionConfigurationCommand,
} from "@aws-sdk/client-lambda";
import {
Expand Down Expand Up @@ -77,7 +78,25 @@ const updateLambda = async (lambda, arnBase, edgeEndpoint) => {
logger.info(res);
};

const getLambdaTags = async (lambda) => {
const lambdaClient = new LambdaClient();
const { Tags } = await lambdaClient.send(
new ListTagsCommand({
Resource: lambda.FunctionArn,
}),
);

return Tags;
};

const saveFunctionInfo = async (lambda, traceStatus) => {
let tags;
try {
tags = await getLambdaTags(lambda);
} catch (e) {
logger.warn(`Failed to get tags for ${lambda.FunctionName}`, e);
}

await put(
{
pk: `function#${process.env.AWS_REGION}#${lambda.FunctionName}`,
Expand All @@ -90,6 +109,7 @@ const saveFunctionInfo = async (lambda, traceStatus) => {
memoryAllocated: lambda.MemorySize,
timeout: lambda.Timeout * 1000,
traceStatus,
tags: tags || {},
},
true,
);
Expand Down

0 comments on commit 65c9578

Please sign in to comment.