DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Amazon Lightsail: Virtual Cloud Server
  • Alexa Skill With .NET Core
  • Implementing CRUD Operations With NLP Using Microsoft.Extensions.AI
  • Accelerate Innovation by Shifting Left FinOps: Part 4

Trending

  • How To Develop a Truly Performant Mobile Application in 2025: A Case for Android
  • How to Convert XLS to XLSX in Java
  • Cosmos DB Disaster Recovery: Multi-Region Write Pitfalls and How to Evade Them
  • Agile and Quality Engineering: A Holistic Perspective
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. .NET on AWS – Persisting Application Data to S3 (Part 2)

.NET on AWS – Persisting Application Data to S3 (Part 2)

In part two of this two-part series, we will build a REST API using .NET to perform CRUD operations for application data storage on S3.

By 
Jawad Hasan Shani user avatar
Jawad Hasan Shani
DZone Core CORE ·
Apr. 13, 23 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
4.6K Views

Join the DZone community and get the full member experience.

Join For Free

In the previous post, we discussed AWS S3 service and its various use cases. We then set up an AWS S3 bucket with configurations and access for our web application data storage requirements. We created a .NET6 WebAPI project and some basic wiring/configuration to allow our application to access S3. However, we still have to write application code that will allow our user to store notes data (files) in an S3 bucket and read the information from these files as well for processing (CRUD operations).

In this post, we will look into how to perform these operations from our .NET application code, along with the use of AWS SDK for S3.

If you haven’t already, I will suggest you read the previous post, as we will be building on that foundation.

AWSSDK.S3 nuget Packages

AWS SDK, available as nuget package, can simplify the code that is needed to interact with Amazon S3 service. We can add it to our solution using the package manager, as shown below:

package manager

You can notice that SDK is very modular, and this structure helps us to import only the package we need for our requirements instead of importing a lot of non-related code.

Domain Model

We have a very simple domain model for our application. The main entity is Note which represents an individual note from a user. We also have another entity NoteSummary which, as the name implies, stores summary information about notes.

Here are the model class for these entities:

model class

Storage Service

Next step, to store and retrieve domain models to and from the S3 bucket, our application needs some code, and that service is defined as the following interface:

Interface

Following is the S3NoteStorageService implementation for this interface:
S3NoteStorageService

As you can see, this implementation uses the IAmazonS3 object, which is the abstraction provided by AWSSDK.S3 nuget package we added earlier.

We’ll not go into the details of these methods' code. The code is self-explanatory, and you can check it from this GitHub repository.

Also, I added the following line in the Program.cs file to enable Dependency injection of this service in our application:

line in the Program.cs file

Next, let's focus on the Controller side to wire all this up.

API Controller

The following screenshot shows the NotesController code.

NotesController code

As you can see that INotesStorageService is injected via controller injection, and we can now use this service in the various action methods as needed to interact with the S3 service.

My plan is to later update this application with users' logins, but for the sake of simplicity, here I’ve hard-coded the user, so all the notes will be saved under this user for now.

Let's see the code for getting a list of notes for a user:

list of notes for a user

Again, the code here is self-explanatory and very typical controller code, and you can check the code of all the methods in detail from the GitHub repository.

Testing the REST API

Ok, with all these in place, I started the application and used the Postman client tool to test the application.

Adding Note
adding note

This is the request payload to add a note. Once executed, we shall have the following files created in the S3 bucket.

request payload

So, here we have one file for the note itself and the other file for the summary.

Try adding more notes using Postman and see more files will be created in your bucket:

add more notes

List Notes

Next, we can test the API for List notes action as shown below:

List notes action

As you can see, we are getting data from all the notes.

Delete Note

In a similar way, we can test the delete operation by providing NoteID, as shown below:

test the delete operation by providing NoteID

Get Note

Here is the API call to get single Note details by providing a NoteId:

Note details

You can check the source code from this git repository.

Summary

In this post, we covered the .NET application code for our notes application and how it uses AWSSDK to interact with S3. AWSDK simplifies our code by providing us abstractions for easy use in our application code.

We build a very simple REST API that allows us to perform CRUD operations on our domain model.

Our application can now benefit from all the great features of the S3 storage service, and we can easily integrate it with other AWS services for more advanced use cases.

Let me know if you have some comments or questions. Till next time, Happy Coding.

AWS Data storage Web API .NET

Published at DZone with permission of Jawad Hasan Shani. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Amazon Lightsail: Virtual Cloud Server
  • Alexa Skill With .NET Core
  • Implementing CRUD Operations With NLP Using Microsoft.Extensions.AI
  • Accelerate Innovation by Shifting Left FinOps: Part 4

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!