2022-09-19 12:00:09 -04:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { InvokeCommand , LambdaClient , LogType } from "@aws-sdk/client-lambda" ;
2022-09-19 14:05:31 -04:00
/** snippet-start:[javascript.v3.lambda.actions.Invoke] */
2022-09-19 12:00:09 -04:00
const invoke = async ( funcName , payload ) => {
2023-10-17 12:21:27 -04:00
const client = new LambdaClient ( { } ) ;
2022-09-19 12:00:09 -04:00
const command = new InvokeCommand ( {
FunctionName : funcName ,
Payload : JSON . stringify ( payload ) ,
LogType : LogType . Tail ,
} ) ;
const { Payload , LogResult } = await client . send ( command ) ;
const result = Buffer . from ( Payload ) . toString ( ) ;
const logs = Buffer . from ( LogResult , "base64" ) . toString ( ) ;
return { logs , result } ;
} ;
2022-09-19 14:05:31 -04:00
/** snippet-end:[javascript.v3.lambda.actions.Invoke] */
2022-09-19 12:00:09 -04:00
export { invoke } ;