Skip to content

Instantly share code, notes, and snippets.

@asktree
Last active December 9, 2020 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asktree/e5e47f62f46e9ecd349550b322dedeb0 to your computer and use it in GitHub Desktop.
Save asktree/e5e47f62f46e9ecd349550b322dedeb0 to your computer and use it in GitHub Desktop.
async await
export const caller = async (
event: CallerEvent,
context: ServerlessContext,
callback
) => {
// START ur code
logger.info({ event, context });
const { collection, time } = event;
const args = {
collection,
database: "juni_db_prod",
runId: time,
rangeField: "creationTimestamp",
rangeBegin: "2020-12-07T06:36:16.071+00:00",
rangeEnd: "2020-12-09T06:37:16.071+00:00",
};
const invokeExecutor = (args) => {
const params = {
FunctionName: "mongo-extractor-dev-executor", // the lambda function we are going to invoke
InvocationType: "RequestResponse",
Payload: JSON.stringify(args),
};
return lambda.invoke(params).promise();
};
// END ur code
// This....
await invokeExecutor(args)
.then((res) => {
logger.info({ res: res }, "Executor completed");
callback();
})
.catch((err) => logger.error({ error: err }, "Executor failed"));
// Is the same as this...
try {
await invokeExecutor(args);
logger.info({ res }, "Executor completed");
callback();
} catch (e) {
logger.error({ error: err }, "Executor failed");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment