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

9 ビュー (過去 30 日間)
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);
  1 件のコメント
David Reiter
David Reiter 2019 年 3 月 22 日
The exception i got:
Error using readContentFromWebService (line 62)
The server returned the status 403 with message "Forbidden" in response to the request to URL
https://s3.eu-central-1.amazonaws.com/bogie-diagnostic-978814483201/Parametrization/RRX/configWheelWear.mat.

サインインしてコメントする。

採用された回答

Aylin
Aylin 2019 年 3 月 22 日
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.
  3 件のコメント
David Reiter
David Reiter 2019 年 3 月 26 日
Hi again.
I got my new API-Key and guess what?! It worked just fine. Thanks again for your input. Here is the code that worked for me:
% Set up S3 credentials.
MY_ACCESS_KEY_ID = 'my_access_id';
MY_SECRET_ACCESS_KEY = 'my_access_key';
MY_REGION = 'my_region';
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.
% file_key can be obtained directly on S3 when navigating to the deisred file or folder
fds = fileDatastore('s3://<my_bucket>/<file_key>.<file_extendsion>', "ReadFcn", @load,'FileExtensions','.mat');
% Read from a single MAT file.
data = read(fds);
Maitreyee Dey
Maitreyee Dey 2020 年 11 月 25 日
Hi Rylan,
I am trying read parquet file format from S3 using Mac os. Receiving error every time. When I am trying to read csv using windows os is able to do it. But with mac its not working. can you please help? Thanks
%% See the code below
setenv('AWS_ACCESS_KEY_ID', 'my_credentials');
setenv('AWS_SECRET_ACCESS_KEY', 'my_credentials');
setenv('AWS_DEFAULT_REGION', 'EU (Ireland) eu-west-1');
pds = parquetDatastore('s3://{mybucket_path}/');
data = readall(pds);
% Below the error msg i am getting everytime
Error using matlab.io.datastore.ParquetDatastore (line 316)
Cannot find files or folders matching:

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by