AWS Lambda for .NET

repository·master·Indexed 23 days ago

https://github.com/aws/aws-lambda-dotnet

A collection of AWS NuGet packages and Blueprints for building, deploying, and testing AWS Lambda functions using .NET Core. It features Lambda Annotations, a programming model that uses C# Source Generators to reduce boilerplate, provide automatic CloudFormation synchronization, and support idiomatic .NET patterns such as dependency injection via [LambdaStartup] and [FromServices].

Tokens
146.8K
Snippets
306
Records
608
Agent score
82%

What's inside aws-lambda-dotnet

  1. Overview of the Simple Kinesis Firehose Function Project

    master

    This starter project is a template for creating an AWS Lambda function that performs data transformation on records written to an Amazon Kinesis Firehose delivery stream.

    Key components include:

    • Function.cs: Contains the class and the single function handler method.
    • aws-lambda-tools-defaults.json: Contains default argument settings for deployment via Visual Studio or the AWS Lambda CLI tools.
    • A test project (optional, depending on selection).

    Note: After deployment, you must manually configure an Amazon Kinesis Firehose delivery stream to enable data transformations using this deployed Lambda function.

  2. Overview of Amazon.Lambda.DurableExecution.Testing

    master

    The Amazon.Lambda.DurableExecution.Testing package provides tools to test durable functions without deploying to AWS. It offers two primary testing modes:

    1. In-process unit testing: Uses DurableTestRunner<TIn, TOut> to drive a [DurableExecution] handler to a terminal state locally. This exercises the real runtime engine (replay logic, checkpoint batching, etc.) using an in-memory service client.
    2. Integration testing: Uses CloudDurableTestRunner<TIn, TOut> to run tests against functions already deployed to the cloud.

    Both runners share the same inspection API, allowing you to write assertions that work across both local and cloud environments by simply swapping the runner type.

  3. Overview of the DetectImageLabelsServerless Project

    master

    This starter project demonstrates an AWS Lambda function that responds to Amazon S3 events. When a .png or .jpg file is uploaded to the monitored S3 bucket, the function uses Amazon Rekognition to detect labels and subsequently adds those labels as tags to the S3 object.

    The project includes:

    • serverless.template: An AWS CloudFormation Serverless Application Model (SAM) template for declaring functions and AWS resources.
    • Function.cs: The C# class containing the function handler method.
    • aws-lambda-tools-defaults.json: Default argument settings for deployment via Visual Studio or the command line.
  4. Overview of the Amazon Lex Book Trip Bot Sample

    master

    This starter project demonstrates how to implement the Amazon Lex Code Hook Interface using .NET. It provides a sample bot that manages reservations for hotel rooms and car rentals.

    Key components include:

    • Function.cs: The entry point for the Lambda function that selects and executes the appropriate IIntentProcessor.
    • BookCarIntentProcessor: Intent processor for the BookCar intent.
    • BookHotelIntentProcessor: Intent processor for the BookHotel intent.
    • aws-lambda-tools-defaults.json: Default argument settings for Visual Studio and command-line deployment tools.

    To use this sample with compatible Bot, Intent, and Slot models, locate the 'BookTrip' template in the Amazon Lex Console. For detailed setup and testing instructions, refer to the Amazon Lex Getting Started documentation.

  5. Overview of the DetectImageLabels Blueprint

    master

    The DetectImageLabels starter project is an AWS Lambda function designed to process images uploaded to Amazon S3.

    Workflow:

    1. The function responds to S3 events.
    2. It checks if the object is a .png or .jpg file.
    3. It uses Amazon Rekognition to detect labels within the image.
    4. It applies the detected labels as tags to the original S3 object.

    Project Structure:

    • Function.cs: Contains the class and the single function handler method.
    • aws-lambda-tools-defaults.json: Contains default argument settings for Visual Studio and command-line deployment tools.
    • (Optional) A test project for unit testing the handler logic.
  6. Overview of the Amazon Lex Order Flowers Bot Sample

    master

    This starter project implements the Lex Code Hook Interface to power an Amazon Lex bot that helps a flower shop process orders.

    Project Structure:

    • Function.cs: The Lambda entry point. It selects and executes an IIntentProcessor to handle incoming requests.
    • OrderFlowersIntentProcessor: The specific implementation for the OrderFlowers intent.
    • aws-lambda-tools-defaults.json: Contains default argument settings for Visual Studio and CLI deployment.

    Lex Configuration: To use this code, you must configure a Lex Bot, Intent, and Slot model in the Amazon Lex Console that is compatible with the 'OrderFlowers' template. For detailed setup instructions, refer to the Amazon Lex Getting Started documentation.

  7. Overview of Amazon.Lambda.DynamoDBEvents.SDK.Convertor

    master
    The Amazon.Lambda.DynamoDBEvents.SDK.Convertor package provides helper extension methods designed to work with Amazon.Lambda.DynamoDBEvents. It allows you to transform Lambda input event model objects (like DynamoDBEvent) into SDK-compatible output model objects (such as Amazon.DynamoDBv2.Model.AttributeValue). This is essential when you need to process DynamoDB stream events in a Lambda function and then interact with the AWS SDK for .NET using that data.
  8. Overview of the DetectImageLabels F# Starter Project

    master

    This starter project is an F# implementation of an AWS Lambda function that processes images.

    Workflow:

    1. The function is triggered by an Amazon S3 event.
    2. It checks if the object is a .png or .jpg file.
    3. If it is an image, it uses Amazon Rekognition to detect labels.
    4. The detected labels are then added as tags to the original S3 object.

    Project Structure:

    • Function.fs: Contains the function handler method.
    • aws-lambda-tools-defaults.json: Contains default argument settings for Visual Studio and command-line deployment tools.
  9. Project Structure of an Empty AWS Serverless Application

    master

    An empty AWS Serverless Application project generated by this blueprint consists of the following key files:

    • serverless.template: An AWS CloudFormation Serverless Application Model (SAM) template used to declare Lambda functions and other AWS resources.
    • Function.cs: The C# class file containing the logic for the Lambda function(s).
    • Startup.cs: A class used to configure services for dependency injection, applicable to either the Lambda container lifetime or a single function invocation.
    • aws-lambda-tools-defaults.json: Contains default argument settings for deployment via Visual Studio or the command line.
    • (Optional) A test project for unit testing your functions.
  10. Run a Giraffe project as an AWS Lambda

    master

    This project demonstrates how to host a Giraffe F# web application on AWS Lambda using Amazon API Gateway. It utilizes the Amazon.Lambda.AspNetCoreServer NuGet package to translate requests from API Gateway into the ASP.NET Core framework and back again.

    Key Project Files

    • serverless.template: AWS CloudFormation Serverless Application Model (SAM) template for declaring functions and resources.
    • aws-lambda-tools-defaults.json: Default argument settings for Visual Studio and CLI deployment tools.
    • Setup.fs: Contains the bootstrap for ASP.NET Core and Giraffe. It includes the LambdaEntryPoint type used for Lambda execution.
    • AppHandlers.fs: Defines HTTP handler functions and routing.
    • web.config: Used for local development.
  11. Run an ASP.NET Core Web API as an AWS Lambda

    master

    You can run an ASP.NET Core Web API project as an AWS Lambda function by using the Amazon.Lambda.AspNetCoreServer NuGet package. This package provides a Lambda function that translates incoming requests from Amazon API Gateway into the ASP.NET Core framework and translates the ASP.NET Core responses back to API Gateway.

    Key components in a typical project structure:

    • LambdaEntryPoint.cs: A class that derives from a base class provided by Amazon.Lambda.AspNetCoreServer. This file bootstraps the ASP.NET Core hosting framework and defines the Lambda function.
    • LocalEntryPoint.cs: Contains the Main function used for local development, bootstrapping the framework with Kestrel.
    • Startup.cs: The standard ASP.NET Core Startup class for service configuration.
    • serverless.template: An AWS CloudFormation Serverless Application Model (SAM) template for declaring resources.
  12. Understand the Step Functions Hello World starter project structure

    master

    This starter project demonstrates a serverless workflow using AWS Step Functions and AWS Lambda. The key components are:

    • serverless.template: An AWS CloudFormation template for declaring Lambda functions and AWS resources.
    • state-machine.json: The definition of the Step Function state machine.
    • StepFunctionTasks.cs: Contains the Lambda functions called as tasks within the state machine.
    • State.cs: Represents the state maintained between Lambda function calls in the Step Function execution.
    • aws-lambda-tools-defaults.json: Contains default argument settings for Visual Studio and command-line deployment tools.

    The workflow consists of 2 Lambda functions called in sequence. The state is passed via the State object. The first Lambda function returns a wait time to demonstrate how to configure a wait step in the state machine.