Skip to content

Commit fb2eae8

Browse files
committed
feat(lambda-logs): enhance function name resolution in nested stacks
1 parent cebb9c2 commit fb2eae8

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lib/configureLambdaLogs.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,22 @@ class ConfigureLambdaLogs {
174174
// Function might be in a nested stack
175175
for (const nestedStack of nestedStacks) {
176176
const nestedStackName = nestedStack.logicalId;
177-
// Check if we have a reference to a function with this name in the nested stack
178-
if (nestedStackName.includes(functionName.replace(/_/g, 'Underscore'))) {
177+
// Get the normalized function name for different possible formats
178+
const normalizedFuncName = functionName.replace(/_/g, 'Underscore');
179+
const stageName = this.serverless.service.provider.stage;
180+
const serviceName = this.serverless.service.service;
181+
182+
// Create variations of the function name to check against
183+
const nameVariations = [
184+
normalizedFuncName, // Base name
185+
`${normalizedFuncName}${stageName}`, // With stage
186+
`${normalizedFuncName}Dash${stageName}`, // With dash and stage
187+
`${serviceName}${normalizedFuncName}`, // With service name
188+
`${serviceName}Dash${stageName}Dash${normalizedFuncName}` // Full format
189+
];
190+
191+
// Check if any name variation is included in the nested stack name
192+
if (nameVariations.some(name => nestedStackName.includes(name))) {
179193
this.serverless.cli.log(`Found potential nested stack for function ${functionName}: ${nestedStackName}`);
180194

181195
// Create a reference to the resource in the nested stack
@@ -285,6 +299,11 @@ class ConfigureLambdaLogs {
285299
// Store the configuration to use in the updateLoggingPostDeploy phase
286300
if (!this._nestedStackConfigs) this._nestedStackConfigs = {};
287301
this._nestedStackConfigs[functionName] = loggingConfig;
302+
303+
// Debug log for nested stack detection
304+
this.serverless.cli.log(`Configuration stored for post-deployment update: ${JSON.stringify(loggingConfig)}`);
305+
this.serverless.cli.log(`Function name will resolve to: ${this.getFunctionName(functionName)}`);
306+
this.serverless.cli.log(`Function is in nested stack: ${resource._nestedIn}`);
288307
continue;
289308
}
290309

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-configure-lambda-logs",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Serverless Framework plugin to configure Lambda logging settings",
55
"main": "src/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)