Goa.Clients.Lambda 0.0.3-preview.1

This is a prerelease version of Goa.Clients.Lambda.
dotnet add package Goa.Clients.Lambda --version 0.0.3-preview.1
                    
NuGet\Install-Package Goa.Clients.Lambda -Version 0.0.3-preview.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Goa.Clients.Lambda" Version="0.0.3-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Goa.Clients.Lambda" Version="0.0.3-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="Goa.Clients.Lambda" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Goa.Clients.Lambda --version 0.0.3-preview.1
                    
#r "nuget: Goa.Clients.Lambda, 0.0.3-preview.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Goa.Clients.Lambda@0.0.3-preview.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Goa.Clients.Lambda&version=0.0.3-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Goa.Clients.Lambda&version=0.0.3-preview.1&prerelease
                    
Install as a Cake Tool

Goa.Clients.Lambda

Lambda client for function invocation in high-performance AWS Lambda functions. This package provides a lightweight, AOT-ready Lambda client optimized for minimal cold start times.

Installation

dotnet add package Goa.Clients.Lambda

Features

  • Native AOT support for faster Lambda cold starts
  • Minimal dependencies and memory allocations
  • Built-in error handling with ErrorOr pattern
  • Support for synchronous and asynchronous invocations
  • Support for dry-run validation
  • Type-safe payload handling with JSON serialization

Usage

Basic Setup

using Goa.Clients.Lambda;
using Microsoft.Extensions.DependencyInjection;

// Register Lambda client
services.AddLambda();

// Or with custom configuration
services.AddLambda(config =>
{
    config.ServiceUrl = "http://localhost:3001"; // For LocalStack
    config.Region = "us-west-2";
    config.LogLevel = LogLevel.Debug;
});

Synchronous Invocation

using System.Text.Json;
using ErrorOr;
using Goa.Clients.Lambda;
using Goa.Clients.Lambda.Operations.Invoke;

public class WorkflowService
{
    private readonly ILambdaClient _lambda;
    
    public WorkflowService(ILambdaClient lambda)
    {
        _lambda = lambda;
    }
    
    public async Task<ErrorOr<ProcessResult>> ProcessDataAsync(ProcessRequest request)
    {
        var invokeRequest = new InvokeRequest
        {
            FunctionName = "data-processor",
            Payload = JsonSerializer.Serialize(request)
        };
        
        var result = await _lambda.InvokeSynchronousAsync(invokeRequest);
        
        if (result.IsError)
            return result.FirstError;
            
        // Deserialize the response payload
        var response = result.Value;
        if (response.Payload != null)
        {
            var processResult = JsonSerializer.Deserialize<ProcessResult>(response.Payload);
            return processResult;
        }
        
        return ErrorOr.Error.Failure("EmptyResponse", "No payload returned from function");
    }
}

Asynchronous Invocation

using Goa.Clients.Lambda.Operations.InvokeAsync;

public async Task<ErrorOr<Success>> TriggerBackgroundTaskAsync(BackgroundTask task)
{
    var invokeRequest = new InvokeAsyncRequest
    {
        FunctionName = "background-processor",
        Payload = JsonSerializer.Serialize(task)
    };
    
    var result = await _lambda.InvokeAsynchronousAsync(invokeRequest);
        
    if (result.IsError)
    {
        Console.WriteLine($"Failed to invoke function: {result.FirstError}");
        return result.FirstError;
    }
    
    return ErrorOr.Success;
}

Synchronous with Event Invocation Type

using Goa.Clients.Lambda.Models;

public async Task<ErrorOr<Success>> TriggerEventAsync(EventData eventData)
{
    var invokeRequest = new InvokeRequest
    {
        FunctionName = "event-processor",
        InvocationType = InvocationType.Event,
        Payload = JsonSerializer.Serialize(eventData)
    };
    
    var result = await _lambda.InvokeSynchronousAsync(invokeRequest);
    return result.IsError ? result.FirstError : ErrorOr.Success;
}

Dry Run Validation

using Goa.Clients.Lambda.Operations.InvokeDryRun;

public async Task<ErrorOr<bool>> ValidateInvocationAsync(string functionName)
{
    var dryRunRequest = new InvokeDryRunRequest
    {
        FunctionName = functionName,
        Payload = "{\"test\": true}"
    };
    
    var result = await _lambda.InvokeDryRunAsync(dryRunRequest);
    
    if (result.IsError)
    {
        Console.WriteLine($"Validation failed: {result.FirstError}");
        return false;
    }
    
    return true; // Validation successful
}

Advanced Options

public async Task<ErrorOr<string>> InvokeWithAdvancedOptionsAsync()
{
    var invokeRequest = new InvokeRequest
    {
        FunctionName = "my-function",
        Qualifier = "PROD", // Version or alias
        LogType = LogType.Tail, // Include logs in response
        ClientContext = "eyJjdXN0b20iOiJkYXRhIn0=", // Base64 encoded context
        Payload = "{\"input\": \"data\"}"
    };
    
    var result = await _lambda.InvokeSynchronousAsync(invokeRequest);
    
    if (result.IsError)
        return result.FirstError;
    
    var response = result.Value;
    
    // Check for function errors
    if (response.FunctionError != null)
    {
        return ErrorOr.Error.Failure("FunctionError", $"Function returned error: {response.FunctionError}");
    }
    
    // Access logs if requested
    if (!string.IsNullOrEmpty(response.LogResult))
    {
        var logs = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(response.LogResult));
        Console.WriteLine($"Function logs: {logs}");
    }
    
    return response.Payload ?? "";
}

Error Handling

var result = await _lambda.InvokeSynchronousAsync(invokeRequest);

if (result.IsError)
{
    // Handle client errors (network, auth, etc.)
    foreach (var error in result.Errors)
    {
        Console.WriteLine($"Client Error: {error.Description}");
    }
    return;
}

var response = result.Value;

// Check for function execution errors
if (response.FunctionError != null)
{
    Console.WriteLine($"Function Error Type: {response.FunctionError}");
    Console.WriteLine($"Function Error Payload: {response.Payload}");
}

// Check HTTP status
if (response.StatusCode != 200 && response.StatusCode != 202)
{
    Console.WriteLine($"Unexpected status code: {response.StatusCode}");
}

Available Operations

  • InvokeSynchronousAsync: Invoke function and wait for response
  • InvokeAsynchronousAsync: Fire-and-forget asynchronous invocation
  • InvokeDryRunAsync: Validate invocation without executing the function

Documentation

For more information and examples, visit the main Goa documentation.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.3-preview.1 46 8/23/2025
0.0.2-preview.2.3 111 8/18/2025
0.0.2-preview.2.2 117 8/17/2025
0.0.2-preview.2.1 87 8/17/2025
0.0.2-preview.2 113 8/9/2025
0.0.0-alpha.0.32 77 12/7/2024
0.0.0-alpha.0.20 71 10/27/2024