Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

ReadMe.md

λ#

LambdaSharp CloudWatch Event Source

Before you begin, make sure to setup your LambdaSharp CLI.

Module Definition

Creating a function that is invoked by a CloudWatch Event is straightforward. Simply add an EventBus source and define an event Pattern to listen to.

Learn more about event patterns on the official AWS documentation site.

Module: Sample.Event
Description: Sample module to demonstrate sending and receiving events
Items:

  - Function: ReceiverFunction
    Description: Lambda function for receiving CloudWatch events
    Memory: 256
    Timeout: 30
    Sources:
      - EventBus: default
        Pattern:
          Source:
            - MySample
          DetailType:
            - MyEvent

Function Code

CloudWatch Event messages can parsed by using the ALambdaEventFunction<T> base class.

public sealed class Function : ALambdaEventFunction<EventDetails> {

    //--- Methods ---
    public override async Task InitializeAsync(LambdaConfig config) { }

    public override async Task<FunctionResponse> ProcessMessageAsync(EventDetails eventDetails) {
        vat request = CurrentEvent;
        LogInfo($"Version = {request.Version}");
        LogInfo($"Account = {request.Account}");
        LogInfo($"Region = {request.Region}");
        LogInfo($"Detail = {LambdaSerializer.Serialize(eventDetails)}");
        LogInfo($"DetailType = {request.DetailType}");
        LogInfo($"Source = {request.Source}");
        LogInfo($"Time = {request.Time}");
        LogInfo($"Id = {request.Id}");
        LogInfo($"Resources = [{string.Join(",", request.Resources ?? Enumerable.Empty<string>())}]");
    }
}