Skip to content

Commit 0656c46

Browse files
committed
simplify running lambda locally
1 parent b1a78f8 commit 0656c46

File tree

3 files changed

+8
-45
lines changed

3 files changed

+8
-45
lines changed

ab-testing/notification-lambda/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ install dependencies:
2222

2323
Call the `run.ts` script (this will send emails to owners of tests which are close to expiry or which have expired in your local [/ab-testing/config/abTests.ts](/ab-testing/config/abTests.ts) file):
2424

25+
```bash
26+
pnpm dev
27+
```
28+
29+
or
30+
2531
```bash
2632
node src/run.ts
2733
```

ab-testing/notification-lambda/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.ts",
66
"type": "module",
77
"scripts": {
8+
"dev": "node src/run.ts",
89
"build": "rollup -c rollup.config.js",
910
"test": "node --test --experimental-test-module-mocks --test-reporter spec './**/*.test.ts'",
1011
"lint": "eslint .",

ab-testing/notification-lambda/src/run.ts

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,16 @@
99
* - AWS credentials for the frontend account must be configured
1010
*/
1111

12-
import type { CloudFormationCustomResourceEvent, Context } from "aws-lambda";
1312
import { handler } from "./index.ts";
1413

1514
process.env.EMAIL_DOMAIN = `abtesting.code.dev-gutools.co.uk`;
1615

17-
// Create a mock CloudFormation event
18-
const mockEvent: CloudFormationCustomResourceEvent = {
19-
RequestType: "Create",
20-
ServiceToken:
21-
"arn:aws:lambda:eu-west-1:123456789012:function:mock-function",
22-
ResponseURL:
23-
"https://cloudformation-custom-resource-response.s3.amazonaws.com/mock-url",
24-
StackId:
25-
"arn:aws:cloudformation:eu-west-1:123456789012:stack/mock-stack/mock-id",
26-
RequestId: "mock-request-id",
27-
LogicalResourceId: "MockResource",
28-
ResourceType: "Custom::DictionaryDeployer",
29-
ResourceProperties: {
30-
ServiceToken:
31-
"arn:aws:lambda:eu-west-1:123456789012:function:mock-function",
32-
},
33-
};
34-
35-
// Create a mock Lambda context
36-
const mockContext: Context = {
37-
callbackWaitsForEmptyEventLoop: false,
38-
functionName: "ab-testing-notification-lambda-local",
39-
functionVersion: "$LATEST",
40-
invokedFunctionArn:
41-
"arn:aws:lambda:eu-west-1:123456789012:function:mock-function",
42-
memoryLimitInMB: "512",
43-
awsRequestId: "mock-request-id",
44-
logGroupName: "/aws/lambda/ab-testing-notification-lambda-local",
45-
logStreamName: "2025/11/19/[$LATEST]mock-stream",
46-
getRemainingTimeInMillis: () => 300000,
47-
done: () => {},
48-
fail: () => {},
49-
succeed: () => {},
50-
};
51-
5216
console.log(`Running lambda handler locally\n`);
5317
console.log(`EMAIL_DOMAIN=${process.env.EMAIL_DOMAIN}\n`);
5418

55-
// Run the handler
56-
// Cast to unknown then to the correct function type to work around typing issues
57-
const runHandler = handler as unknown as (
58-
event: CloudFormationCustomResourceEvent,
59-
context: Context,
60-
callback: () => void,
61-
) => Promise<void>;
62-
6319
void (async () => {
6420
try {
65-
await runHandler(mockEvent, mockContext, () => {});
21+
await handler();
6622
console.log("\n✅ Lambda handler completed successfully");
6723
process.exit(0);
6824
} catch (error) {

0 commit comments

Comments
 (0)