Skip to main content

snippets_js

Integration

New integration from credential
const awsLambdaClient = yepcode.integration.awsLambda("credential-slug");
New integration from plain authentication data
const { LambdaClient } = require("@aws-sdk/client-lambda");

const awsLambdaClient = new LambdaClient({
credentials: {
accessKeyId: "accessKeyId",
secretAccessKey: "secretAccessKey",
},
});

List Functions

List functions
const { ListFunctionsCommand } = require('@aws-sdk/client-lambda')
const listFunctionsCommand = new ListFunctionsCommand({});

const { Functions } = await awsLambdaClient.send(listFunctionsCommand);
for(const func of Functions) {
console.log(func.FunctionName, func.Description)
}

Invoke Function

Invoke function
const { InvokeCommand, LogType } = require('@aws-sdk/client-lambda')

try {
const params = {
FunctionName: 'funcName',
Payload: JSON.stringify({ foo: 'bar' }),
LogType: LogType.Tail
}
const invokeCommand = new InvokeCommand(params)
const { Payload, LogResult } = await awsLambdaClient.send(invokeCommand)
const result = Buffer.from(Payload).toString()
const logs = Buffer.from(LogResult, 'base64').toString()

console.log(result)
console.log(logs)
} catch (error) {
throw error
} finally {
// if you are using a custom http handler, you may call destroy() to close open connections.
client.destroy()
}

Get Function

Get function
const { GetFunctionCommand } = require("@aws-sdk/client-lambda");
const getFunctionCommand = new GetFunctionCommand({ FunctionName: 'funcName' });
const response = await awsLambdaClient.send(getFunctionCommand)
console.log(response);