MATLAB: How can i access .mat files, stored in an encrypted amazon S3 bucket via Matlab (API Key available)

api-keyawsremote dataweboptionswebread

Using Matlab R2018b on Windows 7
Already tried the following:
url = "https://se.eu-central-1.amazonaws.com/my_bucket/my_file.mat";
opt = weboptions('keyName','my_key_id','keyValue','my_api_key');
file = webread(url,opt);

Best Answer

Hi David, it might be easier to use FileDatastore with the load function to do this:
% Set up S3 credentials.
setenv('AWS_ACCESS_KEY_ID', MY_ACCESS_KEY_ID);
setenv('AWS_SECRET_ACCESS_KEY', MY_SECRET_ACCESS_KEY);
setenv('AWS_REGION', MY_REGION);
% Construct a FileDatastore with a S3 URI.
fds = fileDatastore("s3://rdmello/*.mat", "ReadFcn", @load);
% Read from a single MAT file.
data = read(fds);
% Read all the data from all the MAT files on S3.
all_data = readall(fds);
Note here that MY_ACCESS_KEY_ID, MY_SECRET_ACCESS_KEY, and MY_REGION are strings that you need to provide in your code. See the Working with Remote Data doc page for more information about this.
Using a datastore here provides some benefits...each file on Amazon S3 is only downloaded only when needed, and you can build a tall array over it for easier scalability on parallel clusters.