In previous Post on this topic, we started by publishing a .NET Core API to AWS Lambda function.
Today, we will extend the API and add more functionality to it (database operations) and then redeploy it to AWS Lambda and see how it goes.
We’ll be using Postgres database (AWS RDS) for data persistence. I’ve written few posts on this topic, which you can check and these will provide you all the background information you need to work with PostgreSQL database in .NET Core:
- AWS Relational Database Service (RDS) — PostgreSQL in Cloud
- Fun with SQL using Postgres and Azure Data Studio
- Fasten your Data Layer with Dapper (A .NET Micro ORM)
Also, I will be using Dapper as an ORM, but feel free to use EntityFramework if you want to.
So, I’ve setup a PostgreSQL (RDS) database and created products and users tables as shown below:
As you can see that I’ve also populated some initial data in the database.
.NET Core API with RDS Database
On the .NET Core Application side, I have added two new projects (.NET Standard class libraries) and installed the Dapper NuGet package to dempApp.Data project as shown below:
demoApp.Data project will also house the Repositories, which will be injected and used in the controller.
We could have added all these items in the API project, but having separate projects (libraries) will help us with separation of concern and easy to manage complexity when application grows.