Skip to content

Commit fccf074

Browse files
authored
Fix integration test failing on first Dependabot PR run (#692)
Fix integration test failing on first Dependabot PR run When custom Lambda layers are defined, Serverless Framework calls CloudFormation.describeStacks in compareWithLastLayer() to check whether the layer has already been uploaded. Its error handler only silences "does not exist" responses; any other error – including the "security token invalid" response AWS returns when credentials are absent – is re-thrown, failing sls package. Add a lightweight test-only Serverless plugin (offline.js) that intercepts CloudFormation.describeStacks during packaging and returns a synthetic "does not exist" error. This makes compareWithLastLayer treat every run as a fresh stack, which is the correct behaviour for snapshot tests where we never actually deploy. The snapshot output is unchanged because S3 key timestamps are already normalised. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Update integration_tests/offline.js Co-authored-by: Ava Silver <ava.silver@datadoghq.com> Co-authored-by: yiming.luo <yiming.luo@datadoghq.com>
1 parent a812da7 commit fccf074

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

integration_tests/offline.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
/**
4+
* Serverless plugin that intercepts CloudFormation.describeStacks during packaging.
5+
*
6+
* When custom Lambda layers are defined, Serverless Framework calls
7+
* CloudFormation.describeStacks in compareWithLastLayer() to check whether a
8+
* layer has already been uploaded (an optimisation to avoid re-uploading
9+
* unchanged layers). The error handler in that function only silences errors
10+
* whose message contains "does not exist"; any other error – including the
11+
* "The security token included in the request is invalid" response AWS returns
12+
* when credentials are absent or invalid – is re-thrown, causing sls package
13+
* to fail.
14+
*
15+
* In snapshot tests we never deploy, so this optimisation is meaningless.
16+
* This plugin intercepts the describeStacks call and immediately returns a
17+
* synthetic "does not exist" error, which the Serverless handler treats as a
18+
* fresh stack and skips the comparison entirely. The rest of the packaging
19+
* lifecycle is unaffected.
20+
*
21+
* This shim exists because Serverless Framework has no credential-free packaging mode
22+
* when custom layers are defined. Tracked upstream:
23+
* https://github.com/serverless/serverless/issues/8187 (root cause, open since 2020)
24+
* https://github.com/serverless/serverless/issues/12969 (feature request for --artifacts-only)
25+
* If either issue is resolved, this plugin can be removed.
26+
*/
27+
class OfflinePackaging {
28+
constructor(serverless) {
29+
this.serverless = serverless;
30+
this.hooks = {
31+
'before:package:compileLayers': () => this.patchProvider(),
32+
};
33+
}
34+
35+
patchProvider() {
36+
const provider = this.serverless.getProvider('aws');
37+
const original = provider.request.bind(provider);
38+
provider.request = (service, method, params, options) => {
39+
if (service === 'CloudFormation' && method === 'describeStacks') {
40+
const stackName = (params && params.StackName) || 'unknown';
41+
return Promise.reject(new Error(`Stack with id ${stackName} does not exist`));
42+
}
43+
return original(service, method, params, options);
44+
};
45+
}
46+
}
47+
48+
module.exports = OfflinePackaging;

integration_tests/serverless-extension.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ frameworkVersion: "3"
33

44
plugins:
55
- ../dist/src
6+
- ./offline
67

78
provider:
89
name: aws

0 commit comments

Comments
 (0)