Amazon ECS (Linux Container) Using AWS Fargate - ASP.NET Core Reporting App Deployment
- 6 minutes to read
This topic uses Microsoft Visual Studio UI to create, dockerize, and deploy a sample ASP.NET Core Devexpress reporting application that includes Document Viewer and Report Designer. The application is deployed to Amazon ECS (Linux containers) using AWS Fargate.
Amazon ECS with AWS Fargate is a fully managed container service that deploys Linux container images.
In this example, the ASP.NET Core application is deployed to Amazon ECS using an existing Dockerfile from Microsoft Visual Studio UI. This method publishes the application as a container image on Linux.
Document Viewer Cache Concerns
To avoid unnecessary document creation operations, the Document Viewer and Report Designer (Preview mode) need access to document pages during the document creation process. This task requires a report and document cache. The cache temporarily stores information between requests made to the server-based document generation service.
For more information on caching and document creation mechanisms, refer to the following help topics:
AWS Fargate is a distributed computing environment that uses parallel computing. Therefore, it is essential to use AWS native storage for caching. This is because only AWS can properly manage requests to the database.
In this example, we will create a PostgreSQL database in the AWS RDS Service (Amazon Relational Database Service) and connect to that database to store and cache reports and documents.
Prerequisites
- Active AWS IAM Credentials.
- Visual Studio 2022 with the ASP.NET and web development workload.
- AWS Toolkit for Visual Studio installed.
- Node.js (LTS version).
- The latest version of Docker desktop. You can find more information about Docker in the following topic: Get Docker.
- Your personal DevExpress NuGet credentials. Refer to the following help topic for instructions on how to obtain the feed URL and authorization key: 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 Sample ASP.NET Core DevExpress Reporting Application
Create a sample .NET application with a Report Designer and Document Viewer components. The project uses a Debian-based Docker image and XPO-based cache for reports and related documents.
- From the File menu, select New > Project.
- Select the DevExpress v24.1 Web App Template Gallery, and click Next.
- In the Configure your new project dialog, specify a project name and location, and click Create.
Select Reporting Application from the .NET category in the invoked DevExpress Template Gallery:
Select the framework version and click Create Project.
Use the DevExpress Template Gallery to generate a basic ASP.NET Core application that contains the End-User Report Designer and Document Viewer components. In the DevExpress ASP.NET Core Project Wizard dialog specify the following settings:
DevExpress ASP.NET Core Project Wizard Setting Value Add Viewer Page True Add Designer Page True Enable Rich Text Editor True Enable Docker Support Based on Selected OS Debian Specify Document Cache Storage Type XPO
For more information, review the following help article: Use Visual Studio Templates to Create an ASP.NET Core Application with a Report Designer.
Specify the NuGet Feed URL for Docker
To restore NuGet packages while building a Docker image, replace the contents of the secrets.dev.yaml
file located in the project with your personal DevExpress NuGet feed URL.
Create the Amazon RDS Database
- Open the AWS Management Console and navigate to the Amazon RDS dashboard. Open the Databases panel and click Create Database.
On the Create database page, select the following options:
Option Value Choose a databse creation method Easy create Configuration PostgreSQL DB Instance size Free tier DB instance identifier database-1 Master username postgres Enter master password in the corresponding field.
- Click the Create database button.
- Upon successful database creation, you may grant public access to the database. To do this, click the database name, click the Connectivity & security tab, and click the Modify button. On the Modify DB instance: database-1 page, scroll down to the Connectivity pane, expand the Additional configuration pane, and select the Publicly accessible radio button. Click the Continue button and, on the next page, click the Modify DB instance button to apply changed settings.
- You may use any Postgres utility, such as pgAdmin, to test connection to the database. Click the database name on the Databases dashboard and switch to the Connectivity & security tab. On this tab, the value displayed as ‘Endpoint’ is the ‘Hostname/address’ value that should be specified for a new connection in pgAdmin.
Install PostgreSQL NuGet Packages
In Visual Studio, open the NuGet Package Manager window and install the following packages:
Specify Database Connection Strings in the Application
Open the appsettings.json
file and replace the "DocumentViewerStorageConnectionString"
connection string value with the following connection string:
XpoProvider=Postgres;Server=database-1.{---}.rds.amazonaws.com;User ID=postgres;Password=***;Database=ReportingViewerStorage;
Replace the "ReportsDataConnectionString"
connection string value with the following connection string:
"Host=database-1.{---}.rds.amazonaws.com;Port=5432;Username=postgres;Password=***;Database=ReportStorage;"
In the above connection strings, use the Endpoint
value that appears on the AWS Databases dashboard instead of the `database-1.{—}.rds.amazonaws.com’ string. Use the password you specified for the database connection.
Set Up a Publishing Profile for AWS Fargate
- In Visual Studio, open the AWS Explorer window, and Log in to the AWS account.
Right-click the project name in the Solution Explorer window and select Publish to AWS:
In the Publish to AWS window, select the ASP.NET Core App to Amazon ECS using AWS Fargate option:
Click Edit settings and specify the Project Build options as follows:
Option Value Docker Build Args –secret id=dxnuget,source=secrets.dev.yaml Docker Execution Directory .
Publish the Application
Click Publish to start deployment. Note that initial publishing takes longer because it creates a new ECS service. The Publish to AWS action adds a Dockerfile to the project, creates a container, uploads it to Amazon ECR, creates a task definition, and creates an ECS cluster with a default service and task for your container.
Publishing is complete when a green check mark appears at the top and the output of the publishing log stops.
The URL displayed with the Endpoint label in the panel on the right can be used to access the application after it has been successfully published.