Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mongoexpuser/cloudflare-r2-bucket-with-aws-sdk-js-v3

Create, Configure, List and Delete R2 Bucket
https://github.com/mongoexpuser/cloudflare-r2-bucket-with-aws-sdk-js-v3

aws-sdk aws-sdk-js-v3 bucket cloudflare configure create delete list nodejs r2

Last synced: 24 days ago
JSON representation

Create, Configure, List and Delete R2 Bucket

Awesome Lists containing this project

README

        

### Cloudflare-R2-Bucket-With-AWS-SDK-JS-V3




Create/Deploy, Configure, List and Delete Cloudflare R2 Bucket (Object Storage) with AWS SDK for JavaScript/NodeJS V3.




The script can execute the followings:

1) Create/deploy R2 buckets specified in the JSON input file.

2) Put/Add Lifecycle Configuration to the R2 buckets.

3) List all R2 buckets.

4) Delete specified R2 buckets.


### Diagram Depicting R2 Bucket Information and Settings on Cloudflare R2 Console.
![Image description](https://github.com/MongoExpUser/Cloudflare-R2-Bucket-With-AWS-SDK-JS-V3/blob/main/clf-r2.png)

## PURPOSE

* Normally, R2 bucket can be create/deployed, configured, listed and deleted on the Cloudflare console or via Cloudflare CLI (Wrangler).


* R2 bucket can also be deployed via AWS SDK in any language of choice, especially for those who:

1) Are already familiar with AWS SDK and

2) Want to create, configure, list and delete large number of buckets programatically.


* This repository contains code for creating/deploying, configuring, listing and deleting cloudflare R2 bucket (object storage) via AWS SDK for JavaScript/NodeJS V3, from any computer.


* AWS SDK for JavaScript/NodeJS V3 is clean, light weight, fast and it fully supports async-await syntax.

* Also, cloudflare R2 bucket has lower storage cost with no egress fee, which makes it attractive to developers for storage.


## RUNNING the NodeJS script

### To run the script, follow these steps:

1) #### Install NodeJS and @aws-sdk/client-s3 (v3) module, assuming Ubuntu OS and NodeJS v21.x
* sudo apt-get -y update

* sudo apt-get install -y ca-certificates curl gnupg

* sudo mkdir -p /etc/apt/keyrings

* curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

* echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_21.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

* sudo apt-get -y update

* sudo apt-get install -y nodejs


2) #### Download or clone the following files, from this repo, into the current working directory (CWD):

* NodeJS script: index.js

* JSON file: config.json

3) #### Fill in relevant values in config.json file.

* References for config.json :

4) #### Then run the code, assuming sudo access:

* sudo node index.js

# License

Copyright © 2024. MongoExpUser

Licensed under the MIT license.