Create/Deploy, Configure, List and Delete Cloudflare R2 Bucket (Object Storage) with AWS SDK for JavaScript/NodeJS V3.
The script can execute the followings:
-
Create/deploy R2 buckets specified in the JSON input file.
-
Put/Add Lifecycle Configuration to the R2 buckets.
-
List all R2 buckets.
-
Delete specified R2 buckets.
-
Normally, R2 bucket can be created/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:
- Are already familiar with AWS SDK and
- Want to create, configure, list and delete large number of buckets programatically.
- Are already familiar with AWS SDK and
-
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, lightweight, fast and it fully supports the async-await syntax.
-
Also, cloudflare R2 bucket has lower storage cost and no egress fee , which makes it attractive to developers for object storage.
-
- 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
- sudo npm install @aws-sdk/client-s3
- sudo apt-get -y update
-
- NodeJS script: index.js
- JSON file: config.json
- NodeJS script: index.js
-
- References for config.json :
-
- sudo node index.js
- sudo node index.js
Copyright © 2024. MongoExpUser
Licensed under the MIT license.