'AWS Annotations Framework Input Parameters for C#

I'm having trouble getting a Lambda function written using the AWS Annotations Framework to accept input parameters. This is the article I'm using: https://aws.amazon.com/blogs/developer/introducing-net-annotations-lambda-framework-preview/, but it only goes so far. When I publish the functions to Amazon and test clicking the TEST button, the input parameters aren't populated.

This is my function:

[LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
        [LambdaFunction()]
        [HttpApi(LambdaHttpMethod.Get, "/add/{x}/{y}")]
        public int Add(int x, int y, ILambdaContext context)
        {
            context.Logger.LogInformation($"{x} plus {y} is {x + y}");
            return x + y;
        }

and this is the Event JSON within the AWS test harness

enter image description here

The log shows that the parameters have no value:

2022-05-09T10:47:02.435Z 51291252-f7cb-4a1e-9f4a-f7aebdec6b02 info 0 plus 0 is 0

I'm using this as an example, I don't actually need a calculator, but I do need to pass input parameters from an Amazon Connect contact flow and I will be passing in parameters like this:

enter image description here

I've spent a few days Googling and reading articles, but so far I've not found anything that helps, so any assistance is gratefully received!



Solution 1:[1]

Using the HttpApi attribute exposes the Lambda function as a REST API called via some http client. Amazon Connect invokes your Lambda function directly using its own event object documented here https://docs.aws.amazon.com/connect/latest/adminguide/connect-lambda-functions.html#function-contact-flow. In .NET the event object is represented as the Amazon.Lambda.ConnectEvents.ContactFlowEvent type from the Amazon.Lambda.ConnectEvents NuGet package.

Currently the Amazon.Lambda.Annotations has support for breaking up the HTTP API event object to follow typical .NET REST patterns. We haven't done that for other types of event sources like Connect, although this is something we want to do.

You can still use Amazon.Lambda.Annotations for your use case to get the dependency injection and syncing CloudFormation template features by using just the LambdaFunction attribute and then having your function take in the Connect event object. Something like this.

[LambdaFunction()]
public IDictionary<string, string> ProcessConnectContactFlow(Amazon.Lambda.ConnectEvents.ContactFlowEvent contactFlowEvent)
{
    // Process the event

    var response = new Dictionary<string, string>()
    {
        { "Name", "CustomerName" },
        { "Address", "1234 Main Road" },
        { "CallerType", "Patient" }
    };

    return response;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Norm Johanson