Last active
December 9, 2020 21:49
-
-
Save asktree/e5e47f62f46e9ecd349550b322dedeb0 to your computer and use it in GitHub Desktop.
async await
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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