From 740cf02117e89c2b115a04610f26a994d80e6ba1 Mon Sep 17 00:00:00 2001 From: Joseph So Date: Mon, 5 Jan 2026 13:32:40 +1100 Subject: [PATCH 1/2] fix(apig): porting the serverless fix in https://github.com/serverless/serverless/pull/12655/changes to osls --- docs/guides/serverless.yml.md | 2 +- lib/plugins/aws/custom-resources/index.js | 4 +++- .../resources/api-gateway-cloud-watch-role/handler.js | 11 ++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/guides/serverless.yml.md b/docs/guides/serverless.yml.md index a4b9f01b3e..c18d4d7d9c 100644 --- a/docs/guides/serverless.yml.md +++ b/docs/guides/serverless.yml.md @@ -568,7 +568,7 @@ provider: fullExecutionData: true # Optional, whether to write CloudWatch logs for custom resource lambdas as added by the framework - frameworkLambda: true + frameworkLambda: false ``` ### S3 buckets diff --git a/lib/plugins/aws/custom-resources/index.js b/lib/plugins/aws/custom-resources/index.js index 6f07305572..1949e81137 100644 --- a/lib/plugins/aws/custom-resources/index.js +++ b/lib/plugins/aws/custom-resources/index.js @@ -24,7 +24,9 @@ async function addCustomResourceToService(awsProvider, resourceName, iamRoleStat const { serverless } = awsProvider; const providerConfig = serverless.service.provider; - const shouldWriteLogs = providerConfig.logs && providerConfig.logs.frameworkLambda; + + // write custom resource lambda logs by default + const shouldWriteLogs = (providerConfig.logs && providerConfig.logs.frameworkLambda) ?? true; const { Resources } = providerConfig.compiledCloudFormationTemplate; const customResourcesRoleLogicalId = awsProvider.naming.getCustomResourcesRoleLogicalId(); const zipFilePath = path.join( diff --git a/lib/plugins/aws/custom-resources/resources/api-gateway-cloud-watch-role/handler.js b/lib/plugins/aws/custom-resources/resources/api-gateway-cloud-watch-role/handler.js index 58a59def90..9724717667 100644 --- a/lib/plugins/aws/custom-resources/resources/api-gateway-cloud-watch-role/handler.js +++ b/lib/plugins/aws/custom-resources/resources/api-gateway-cloud-watch-role/handler.js @@ -1,5 +1,11 @@ 'use strict'; +/** + * IMPORTANT: This file is cached, so when you test changes made to this file, + * make sure you delete the .serverless directory, and un-memoize the packaging code. + * For more info search for the "utils/ensure-artifact.js" file in the codebase. + */ + const { wait, MAX_AWS_REQUEST_TRY } = require('../utils'); const { getEnvironment, handlerWrapper } = require('../utils'); const { @@ -52,7 +58,10 @@ async function create(event, context) { return (await iam.send(new ListAttachedRolePoliciesCommand({ RoleName: roleName }))) .AttachedPolicies; } catch (error) { - if (error.code === 'NoSuchEntity') { + if ( + error.code === 'NoSuchEntity' || + error.message.includes('cannot be found') + ) { // Role doesn't exist yet, create; await iam.send( new CreateRoleCommand({ From 17cec29cbe9f27fdec1ff5436c1c42d9dd23bdf9 Mon Sep 17 00:00:00 2001 From: Joseph So Date: Wed, 7 Jan 2026 12:43:24 +1100 Subject: [PATCH 2/2] reverse the change based on feedback --- docs/guides/serverless.yml.md | 2 +- lib/plugins/aws/custom-resources/index.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/guides/serverless.yml.md b/docs/guides/serverless.yml.md index c18d4d7d9c..a4b9f01b3e 100644 --- a/docs/guides/serverless.yml.md +++ b/docs/guides/serverless.yml.md @@ -568,7 +568,7 @@ provider: fullExecutionData: true # Optional, whether to write CloudWatch logs for custom resource lambdas as added by the framework - frameworkLambda: false + frameworkLambda: true ``` ### S3 buckets diff --git a/lib/plugins/aws/custom-resources/index.js b/lib/plugins/aws/custom-resources/index.js index 1949e81137..6f07305572 100644 --- a/lib/plugins/aws/custom-resources/index.js +++ b/lib/plugins/aws/custom-resources/index.js @@ -24,9 +24,7 @@ async function addCustomResourceToService(awsProvider, resourceName, iamRoleStat const { serverless } = awsProvider; const providerConfig = serverless.service.provider; - - // write custom resource lambda logs by default - const shouldWriteLogs = (providerConfig.logs && providerConfig.logs.frameworkLambda) ?? true; + const shouldWriteLogs = providerConfig.logs && providerConfig.logs.frameworkLambda; const { Resources } = providerConfig.compiledCloudFormationTemplate; const customResourcesRoleLogicalId = awsProvider.naming.getCustomResourcesRoleLogicalId(); const zipFilePath = path.join(