Skip to main content
All docs
V24.2

Lambda Annotations Framework App with DevExpress Reporting - Create and Deploy

  • 5 minutes to read

In this topic, you will learn how to create and deploy an Amazon Lambda Annotations Framework project that generates a report based on user input and exports the report to a PDF file. This tutorial uses Microsoft Visual Studio.

The Lambda Annotations Framework simplifies AWS Lambda function development for .NET developers. It uses custom C# attributes and source code generators to convert annotated Lambda functions into a regular Lambda programming model.

The AWS CloudFormation stack CDKToolkit is created when you bootstrap your AWS account. This stack is based on the Amazon Linux AMI, a Linux image that already includes the necessary packages for the DevExpress Skia-based drawing engine. Deploying a .NET 8 reporting application using the Lambda Annotations Framework requires no additional Linux image customization.

Prerequisites

  1. .NET 8.0 SDK
  2. Visual Studio 2022 with ASP.NET and web development workload.
  3. An AWS account with an active subscription.
  4. AWS Toolkit for Visual Studio 2022 installed.
  5. The DevExpress NuGet feed registered in your development environment. Refer to the following help topic for more information: Choose Between Offline and Online DevExpress NuGet Feeds.

Important Disclaimer

The deployment recommendations do not apply to all possible configurations and should not be considered comprehensive. We offer these instructions as a getting-started reference. Steps may vary depending on your operating system, installed software, and DevExpress versions. You, the developer, are responsible for the application, database, network, and other configurations based on your client, security, environment, and other requirements. We recommend that you review these settings with your database, network, and IT infrastructure administrators and consider tailoring their recommendations to your case.

Create a New Lambda Annotations Project Using Template

  • From the File menu, select New > Project.
  • Enter AWS Serverless in the template search box.
  • Select the AWS Serverless Application (.NET Core C#) from the search result and click Next:

    Select AWS Serverless Application Template

  • In the Configure your new project dialog, name the project DXReportingAwsLambdaAnnotationsApp and click Next.

  • The Select Blueprint wizard appears. Select the Annotations Framework Sample blueprint and click Finish:

    AWS Lambda Annotation Blueprint Wizard

  • Change the target framework to .NET 8.0 in the project’s Properties window, Application tab.

Install DevExpress NuGet Packages

Open the NuGet Package Manager in Visual Studio and ensure that the DevExpress NuGet feed is registered as the package source. Install the following packages:

DevExpress.Reporting.Core
This package implements core functionality for DevExpress Reporting.
DevExpress.Drawing.Skia
This package implements the cross-platform drawing engine based on the Skia Graphics Library. For more information, review the following help topic: DevExpress.Drawing Graphics Library.

If you are new to NuGet packages, see the following installation guide for assistance: Install DevExpress Packages Using NuGet Package Manager.

Implement Lambda Functions

Open the Functions.cs file and replace the sample lambda functions with a custom default function and a function that creates a report and exports it to PDF. You can replace the content of the Functions.cs file with the following code snippet:

using Amazon.Lambda.Core;
using Amazon.Lambda.Annotations;
using Amazon.Lambda.Annotations.APIGateway;

[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace DXReportingAwsLambdaAnnotationsApp;
public class Functions
{
    [LambdaFunction()]
    [HttpApi(LambdaHttpMethod.Get, "/")]
    public string Default() {
        var docs = @"DevExpress Reporting for Lambda Annotations Framework";
        return docs;
    }

    [LambdaFunction]
    [HttpApi(LambdaHttpMethod.Get, "/report")]
    public async Task<IHttpResult> ExportPDF([FromQuery] string firstName,
        [FromQuery] string lastName, 
        ILambdaContext context) 
    {
        context.Logger.LogInformation("C# HTTP trigger function processed a request.");

        if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName)) {
            return HttpResults.BadRequest("Required query parameters are missing: 'firstName', 'lastName'.");
        }

        using var report = new TestReportsCore.TicketTemplate();
        report.Parameters["firstName"].Value = firstName;
        report.Parameters["lastName"].Value = lastName;

        using var ms = new MemoryStream();
        await report.ExportToPdfAsync(ms);

        var contentType = new KeyValuePair<string, string>("Content-Type", "application/pdf; charset=utf-8");
        return HttpResults.Ok(ms.ToArray()).AddHeader(contentType.Key, contentType.Value);
    }
}

Add a Report Template to the Project

The application instantiates a custom report class, passes parameters specified in the query string, exports the report to PDF, and displays the resulting PDF in the browser. The report is a conference ticket that contains the owner’s name from the query string, a linear bar code, and a QR code to verify the quality of the print.

Ticket Report in a Report Designer

The TicketTemplate report is created in DevExpress Report Designer in a .NET 8 class project that is compiled to the TestReportsCore class library.

The report contains two parameters, “firstName” and “lastName”, which identify the ticket owner and allow you to use the report as a template.

Add a reference to the TestReportsCore.dll library to the current DXReportingAwsLambdaAnnotationsApp project.

Test the Project Locally

The AWS Toolkit for Visual Studio 2022 installs the Mock Lambda Test Tool that enables the developer to debug .NET Lambda function code in Visual Studio. For more information, review the following document: The AWS .NET Mock Lambda Test Tool.

The tool integrates in Visual Studio so you can click the button to run the Mock Lambda Test Tool and test the project:

Mock Lambda Test Tool Button

A page is opened in a browser that enables you to send a sample request and examine the response:

Mock Test Page

You can see that the request was processed successfully. The function works as expected and returns the PDF stream.

Deploy to AWS

With the AWS Toolkit for Visual Studio installed, you can right-click on the DXReportingAwsLambdaAnnotationsApp project in Solution Explorer and select Publish to AWS Lambda to initiate deployment:

Publish to AWS Lambda

A wizard appears that allows you to select the CloudFormation stack name and the S3 bucket used to store compiled deployment packages:

Publish Stack Name Dialog

Test the Published Application

When the application is successfully published, a Visual Studio window is displayed with the information about the stack and the deployed application. The AWS Serverless URL field on the page displays a link to access the published application.

Add the required query string:

/report?firstName=Tommy&lastName=Deer

Press Enter to send the request. The browser displays the resulting PDF file:

Resulting PDF File