How Do I dowload a file from Amazon S3?

Hello,
I am trying to use matlab to download a .gz file from Amazon s3. I have the AWS creditials set.
% Set AWS credentials
YOUR_AWS_ACCESS_KEY_ID = 'test1';
YOUR_AWS_SECRET_ACCESS_KEY = 'test2';
setenv('AWS_ACCESS_KEY_ID', YOUR_AWS_ACCESS_KEY_ID);
setenv('AWS_SECRET_ACCESS_KEY', YOUR_AWS_SECRET_ACCESS_KEY);
setenv('AWS_REGION', 'us-west-2');
I have my path s3 path:
rawdataPath = 's3://companya/Frontier/FieldData/file.csv.gz'
I am wondering how I can download this file.

Answers (1)

Once you have your environment set up, you should be able to treat files on S3 as you would treat any local file, e.g.,
rawdataPath = 's3://companya/Frontier/FieldData/file.csv.gz'
localDir = 'C:\Downloads';
% copy .gz to local directory:
copyfile(rawdataPath,localDir)
% or unzip .gz to local directory:
gunzip(rawdataPath,localDir)

2 Comments

when trying the copyfile() I get a low level error has occured.
Error using copyfile
A low level error has occurred at
's3://companya/Frontier/FieldData/file.csv.gz'.
Error in sc_downloadGZFiles (line 19)
copyfile(rawdataPath,Datapath);
When trying the gunzip() I get
Error using matlab.io.internal.archive.checkFilename>downloadArchiveFile
Function GUNZIP was unable to read URL
Check that your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set correctly.

Sign in to comment.

Categories

Products

Release

R2023b

Tags

Asked:

on 18 Mar 2024

Commented:

on 18 Mar 2024

Community Treasure Hunt

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

Start Hunting!