☝️Small business or a startup? See if you qualify for our special offer.
+

Read data from S3 bucket

Answered
Varun asked on June 19, 2025

Hi,

 

We would like to read csv file from AWS s3 bucket instead of local drive. Could you please share sample code for that?

 

Thanks,

Varun

9 answers

Public
Maksym Diachenko Maksym Diachenko Flexmonster June 19, 2025

Hello, Varun!

Thank you for writing to us.

Flexmonster supports connecting CSV and JSON files from cloud storage, such as AWS S3.
Since S3 files often require authentication, we would like to mention that Flexmonster allows setting request headers with credentials using the requestHeders data source object property.
For reference, you can check this example, which loads a CSV file from our CDN: https://jsfiddle.net/flexmonster/u5Lp4k98/

Please let us know if our answer helped you.

Best Regards,
Maksym

Public
Varun June 19, 2025

Hi Maksym,

 

Thanks for your reply! Does this mean Flexmonster already have inbuilt library to connect AWS S3 bucket and we just need to pass file path like to read csv s3://aligne-rds-sim-refresh-bucket/REFRESH_SIM_01.csv ?

In our case we mainly use AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY and AWS region for authentication.

 

 

Thanks,

Varun

Public
Varun June 19, 2025

Just to be sure we are using FDS to read csv file

Public
Maksym Diachenko Maksym Diachenko Flexmonster June 20, 2025

Hello, Varun!

Thank you for providing additional context.

Flexmonster Data Server does not support connecting to S3 files. However, there are several potential solutions for working with CSV files on S3:

  1. You can implement a server-side script that downloads a CSV file to the server and then proceeds with the default logic for creating a CSV data index.
  2. Alternatively, you can create a custom parser that would be responsible for loading and processing the data without the need for an additional step of downloading its copy to the server. You can find a guide for implementing a custom parser in our documentation: https://www.flexmonster.com/doc/implementing-custom-parser/

Please let us know if one of these approaches would work for you. Also, we would like to know if you are asking about working with CSV files on S3 because it would just be convenient to have, or because it is critically important for your task?

Looking forward to hearing from you.

Best Regards,
Maksym

Public
Varun 6 days ago

Hi,

 

Example you have shown is creating custom index initially i.e. in builder while we are creating index dynamically by using below method

 

public async Task<IActionResult> PostFields([FromBody]FieldsRequest request)

{

    await _createService.CreateIndexIfNotExists(request.Index);

    var response = await _apiService.GetFieldsAsync(request);

    return new JsonResult(response);

}

Since we are storing data into S3 bucket and would like to create a custom dynamic index where we will retrieve csv data in memory stream and then populate it into Pivot Grid.

 

Can it be done? If yes, could you please share .net example for the same?

 

Thanks,

Varun

Public
Maksym Diachenko Maksym Diachenko Flexmonster 3 days ago

Hello, Varun!

Thank you for your reply.
We are working on an example that demonstrates dynamically creating a custom index by loading a CSV file from a URL. We will get back to you once it is ready.

Best Regards,
Maksym

Public
Maksym Diachenko Maksym Diachenko Flexmonster 2 days ago

Hello, Varun!

We have modified the sample .NET project with Flexmonster DLL to include the custom parser, which reads remote CSV files from a URL. The project is available on our GitHub: https://github.com/flexmonster/flexmonster-data-server-dll/tree/csv-url-parser-runtime-index-creation

You can find a quick breakdown of what was added or changed below:

  1. Added CustomParser.cs - CSVURLParser parser implementation, based on the existing CSVParser. Its type is set to "csv_url" to make it distinguishable from other index types, and the Parse() method has been updated to fetch CSV content over HTTPS using HttpClient(see line 72). The implementation can be further adapted for S3 or other sources.
  2. Added CsvUrlIndexOptins class - this class extends the existing CsvIndexOptions. Our implementation only overrides the type; however, you can add further changes to pass more settings, such as AWS credentials.
  3. Integrated runtime index creation into the IndexCreateService.cs - the config for the new index is registered with the CsvUrlIndexOptions.

Please let us know if the provided sample helped you.

Best Regards,
Maksym

Public
Varun 2 days ago

Thanks, Maksym! It works.

Is there a way to find list of all indexes when running FDS as dll and delete them via post command on demand?

Public
Maksym Diachenko Maksym Diachenko Flexmonster 1 day ago

Hello, Varun!

Thank you for your question.

These can be implemented within the dedicated service for managing indexes, or by adding methods to the existing IndexCreateService:

using Flexmonster.DataServer.Core.DataStorages;
using Flexmonster.DataServer.Core;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Flexmonster.DataServer.Core.Parsers;
using System.Collections.Generic;


namespace DemoDataServerCore.Controllers
{
    public class IndexManagementService
    {
        private readonly IDataStorage _dataStorage;
        private readonly DatasourceOptions _datasourceOptions;

        public IndexManagementService(IDataStorage dataStorage, IOptionsMonitor<DatasourceOptions> datasourceOptions)
        {
            _dataStorage = dataStorage;
            _datasourceOptions = datasourceOptions.CurrentValue;
        }

        public Dictionary<string, IndexOptions> GetAllIndexes()
        {
           return _datasourceOptions.Indexes;
        }

        public void DeleteIndex(string indexName)
        {
            if (_datasourceOptions.Indexes.ContainsKey(indexName))
            {
                _datasourceOptions.Indexes.Remove(indexName);
                _dataStorage.Remove(indexName);
            }
        }
    }

}

Note that the service must be registered within the Startup.cs:

services.AddScoped<IndexManagementService>();

These service methods provide a clean abstraction, and you can implement and configure controller endpoints using them.

Please let us know if our answer helped you.

Best Regards,
Maskym

Please login or Register to Submit Answer