Skip to content

Instantly share code, notes, and snippets.

@josefaidt
Created March 20, 2022 14:31
Show Gist options
  • Save josefaidt/f2d9384b5705b1690d12120e100ebd2c to your computer and use it in GitHub Desktop.
Save josefaidt/f2d9384b5705b1690d12120e100ebd2c to your computer and use it in GitHub Desktop.
import { LambdaClient, InvokeCommand } from '@aws-sdk/client-lambda'
/**
* Invoke our Lambda function with a payload
* @param {Object.<string, any>} payload
* @returns {Promise<import('@aws-sdk/client-lambda').InvokeCommandOutput>}
*/
async function invoke(payload) {
/** @type {import('@aws-sdk/client-lambda').LambdaClient} */
const client = new LambdaClient({ region: process.env.REGION })
/** @type {import('@aws-sdk/client-lambda').InvokeCommandInput} */
const input = {
FunctionName: process.env.FUNCTION_MYAMPLIFY_FUNCTION_NAME,
Payload: JSON.stringify(payload),
InvocationType: 'Event',
}
/** @type {import('@aws-sdk/client-lambda').Command} */
const command = new InvokeCommand(input)
/** @type {import('@aws-sdk/client-lambda').InvokeCommandOutput} */
const output = await client.send(command)
return output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment