Skip to content

Commit 2868f1d

Browse files
authored
chore(core): Pass Lambda Context to custom resource handler (#18056)
… passing context object into user handler. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* Fixes #18055
1 parent 621a410 commit 2868f1d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

packages/@aws-cdk/core/lib/custom-resource-provider/nodejs-entrypoint.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ const CREATE_FAILED_PHYSICAL_ID_MARKER = 'AWSCDK::CustomResourceProviderFramewor
1313
const MISSING_PHYSICAL_ID_MARKER = 'AWSCDK::CustomResourceProviderFramework::MISSING_PHYSICAL_ID';
1414

1515
export type Response = AWSLambda.CloudFormationCustomResourceEvent & HandlerResponse;
16-
export type Handler = (event: AWSLambda.CloudFormationCustomResourceEvent) => Promise<HandlerResponse | void>;
16+
export type Handler = (event: AWSLambda.CloudFormationCustomResourceEvent, context: AWSLambda.Context) => Promise<HandlerResponse | void>;
1717
export type HandlerResponse = undefined | {
1818
Data?: any;
1919
PhysicalResourceId?: string;
2020
Reason?: string;
2121
NoEcho?: boolean;
2222
};
2323

24-
export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent) {
24+
export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent, context: AWSLambda.Context) {
2525
external.log(JSON.stringify(event, undefined, 2));
2626

2727
// ignore DELETE event when the physical resource ID is the marker that
@@ -39,7 +39,7 @@ export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent
3939
// cloudformation (otherwise cfn waits).
4040
// eslint-disable-next-line @typescript-eslint/no-require-imports
4141
const userHandler: Handler = require(external.userHandlerIndex).handler;
42-
const result = await userHandler(event);
42+
const result = await userHandler(event, context);
4343

4444
// validate user response and create the combined event
4545
const responseEvent = renderResponse(event, result);

packages/@aws-cdk/core/test/custom-resource-provider/nodejs-entrypoint.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ async function invokeHandler(req: AWSLambda.CloudFormationCustomResourceEvent, u
186186
actualResponse = responseBody;
187187
};
188188

189-
await entrypoint.handler(req);
189+
await entrypoint.handler(req, {} as AWSLambda.Context);
190190
if (!actualResponse) {
191191
throw new Error('no response sent to cloudformation');
192192
}

0 commit comments

Comments
 (0)