-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature request] Allow initializing the AWS Services outside of the handler #230
Comments
Or: maybe documenting memoization patterns that work with this? |
@onyxraven what are the memoization patters you refer to? |
a possibility for (brief, untested) example: let dynamoClient = undefined;
function getDynamoClient() {
if (dynamoClient != undefined) { return dynamoClient; }
return dynamoClient = new AWS.DynamoDB();
}
export function handler(e, c) {
let dynamo = getDynamoClient();
theRest(e);
} |
@onyxraven thank you for your input, but will this work? Does the memoization work between lambda invokations? Intuitively I would say that it doesn't, but I haven't tested it either. Ideally you would be able to use AWS Services as recommended by AWS (i.e. initializing the service outside of the function handler), and aws-sdk-mock would work seamless with that. |
Agree, though order of operations gets tricky, since it will require you to mock the object before the first require of the code so that the execution catches the mock. I'm getting some extra opinion, but as far as I understand, because One note, I didn't touch on that there needs to be a |
I quote from the README:
Now I also quote from the Lambda best practices as published by AWS:
I love this testing package, but it makes me very sad that I have to choose between following Lambda best practices or using this amazing testing framework. I want to initialize AWS services outside of the hanlder so that lambdas (warm) start faster, but then I cannot use
aws-sdk-mock
:(The text was updated successfully, but these errors were encountered: