This Node.js script allows you to download files from an AWS S3 bucket. It's particularly useful for retrieving images or videos from a specified S3 bucket based on the file key.
- Downloads files from an AWS S3 bucket
- Supports environment variable configuration for AWS credentials and bucket name
- Creates necessary directories for downloaded files
- Node.js installed on your system
- AWS account with access to S3 buckets
- AWS access key and secret key
-
Clone this repository or download the script.
-
Navigate to the project directory.
-
Install the required dependencies:
npm install
-
Create a
.envfile in the root directory of the project. -
Add the following environment variables to the
.envfile:ACCESSKEY=your_aws_access_key SECRETKEY=your_aws_secret_key REGION=your_aws_region S3BUCKET=your_s3_bucket_nameReplace the values with your actual AWS credentials and bucket name.
-
Modify the
keyvariable in the script to specify the file you want to download:const key = "your_file_key_here";
-
Run the script:
node index.js -
Example of
S3BUCKETURL format:
https://s3.region.amazonaws.com/bucket-name/key-name
Downloaded files are saved in a downloads directory within the project folder. The script automatically creates any necessary subdirectories based on the file key structure.
The script includes basic error handling and will log any errors encountered during the download process to the console.
Contributions, issues, and feature requests are welcome. Feel free to check the issues page if you want to contribute.