### Invoke a local Lambda function using @vercel/fun Source: https://github.com/vercel/fun/blob/main/README.md This example demonstrates how to use the `@vercel/fun` library to create, invoke, and destroy a local serverless function. It configures the function with a directory, handler, runtime, environment variables, and memory size, then invokes it with a payload and logs the result. The `createFunction` call sets up the local server, and `fn.destroy()` cleans up resources. ```javascript import { createFunction } from '@vercel/fun'; async function main() { // Starts up the necessary server to be able to invoke the function const fn = await createFunction({ Code: { // `ZipFile` works, or an already unzipped directory may be specified Directory: __dirname + '/example' }, Handler: 'index.handler', Runtime: 'nodejs8.10', Environment: { Variables: { HELLO: 'world' } }, MemorySize: 512 }); // Invoke the function with a custom payload. A new instance of the function // will be initialized if there is not an available one ready to process. const res = await fn({ hello: 'world' }); console.log(res); // Prints: { hello: 'world' } // Once we are done with the function, destroy it so that the processes are // cleaned up, and the API server is shut down (useful for hot-reloading). await fn.destroy(); } main().catch(console.error); ``` -------------------------------- ### Supported Runtimes for @vercel/fun Source: https://github.com/vercel/fun/blob/main/README.md This section details the various AWS Lambda runtimes that `ƒun` supports for local development. It specifies the runtime identifiers and their corresponding Node.js or Python versions, or other language specifics like Go and custom runtimes. ```APIDOC Runtimes Supported: - nodejs: Node.js Lambda functions using system `node` binary - nodejs6.10: Node.js Lambda functions using downloaded Node v6.10.0 binary - nodejs8.10: Node.js Lambda functions using downloaded Node v8.10.0 binary - nodejs10.x: Node.js Lambda functions using downloaded Node v10.15.3 binary - nodejs12.x: Node.js Lambda functions using downloaded Node v12.22.7 binary - nodejs14.x: Node.js Lambda functions using downloaded Node v14.18.1 binary - python: Python Lambda functions using system `python` binary - python2.7: Python Lambda functions using downloaded Python v2.7.12 binary - python3: Python Lambda functions using system `python3` binary (or fallback to `python`) - python3.6: Python Lambda functions using downloaded Python v3.6.8 binary - python3.7: Python Lambda functions using downloaded Python v3.7.2 binary - go1.x: Lambda functions written in Go - binary must be compiled for your platform - provided: Custom runtimes ``` -------------------------------- ### Define a basic Node.js Lambda function Source: https://github.com/vercel/fun/blob/main/README.md This snippet shows a simple Node.js Lambda function that returns a 'hello: world' object when invoked. It uses the standard `exports.handler` signature for AWS Lambda, making it compatible with the `ƒun` local runtime. ```javascript // example/index.js exports.handler = function(event, context, callback) { callback(null, { hello: 'world' }); }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.