Skip to content
This repository has been archived by the owner on Sep 4, 2022. It is now read-only.

Commit

Permalink
fix: Resolve handler to improve sub-dir handling
Browse files Browse the repository at this point in the history
fixes aws#15391
  • Loading branch information
setu4993 committed Dec 29, 2021
1 parent eb4cb42 commit 5bfaf9d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/@aws-cdk/aws-lambda-python/lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Construct } from '@aws-cdk/core';
*/
export interface PythonFunctionProps extends FunctionOptions {
/**
* The path to the root directory of the function.
* Path to the source of the function or the location for dependencies.
*/
readonly entry: string;

Expand Down Expand Up @@ -70,6 +70,8 @@ export class PythonFunction extends Function {
throw new Error('Only `PYTHON` runtimes are supported.');
}

const resolvedHandler =`${index.slice(0, -3)}.${handler}`.replace('/', '.');

super(scope, id, {
...props,
runtime,
Expand All @@ -78,7 +80,7 @@ export class PythonFunction extends Function {
runtime,
...props.bundling,
}),
handler: `${index.slice(0, -3)}.${handler}`,
handler: resolvedHandler,
});
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda-python/test/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ test('PythonFunction with index in a subdirectory', () => {
}));

Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
Handler: 'inner/custom_index.custom_handler',
Handler: 'inner.custom_index.custom_handler',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"Arn"
]
},
"Handler": "inner/custom_index.custom_handler",
"Handler": "inner.custom_index.custom_handler",
"Runtime": "python3.7"
},
"DependsOn": [
Expand Down

0 comments on commit 5bfaf9d

Please sign in to comment.