Most developers hit the AWS SDK for the first time buried in documentation with no working example and an error message that makes zero sense. This tutorial does the opposite: it walks through every step from a blank folder to running Node.js code that lists, creates, populates, and deletes S3 buckets using the official aws-sdk npm package.
This is a walkthrough from the Mastering AWS S3 series. The core SDK mechanics covered here have not changed. If you want to control S3 buckets from application code rather than clicking around the console or typing one-off CLI commands, this is the right starting point.
What You’ll Walk Out With
- A working Node.js project with aws-sdk and uuid installed
- AWS credentials properly wired into your code using AWS.config
- Code that lists all your S3 buckets directly from the terminal
- Code that creates a new bucket with a globally unique name every time
- Code that uploads a file into that bucket using the correct putObject method
- Code that lists objects inside any bucket and deletes a bucket when you are done
- A clear mental model of when to reach for the SDK instead of the console or CLI
- Not sure which cloud or coding skill to turn into a freelance offer first? finder.platformproof.com matches your background to the highest-value starting point.
Why Use the SDK Instead of the Console or CLI
The AWS Management Console is great for one-off tasks. The CLI handles scripted operations well. But the moment you need S3 to respond automatically to something happening inside your application, neither option works on its own. You need the SDK running inside your code.
Alston walks through three concrete real-world examples in the video. First: a website where every new user gets their own dedicated S3 bucket created automatically when they register. Second: a blogging platform where each writer’s uploaded images and assets go into a separate bucket. Third: an HR department tool where employees click Save inside a company application and the file lands in the correct bucket automatically, with no manual AWS console interaction.
All three of those require the SDK. Console clicks and CLI commands cannot fire from inside your application at runtime. The aws-sdk npm package is what bridges your Node.js code to the full surface area of Amazon Web Services, including S3, EC2, DynamoDB, and every other service in the AWS catalog. That is also why the install takes a bit longer than most packages. You are pulling in a large library.
Step 1: Install Node.js on Your Machine
Go to nodejs.org and download the current LTS version. The site detects your operating system and offers the right installer. If you are on a Mac, you get a .pkg file. If you are on Windows, you get an .exe. Either way, click through the prompts and Node.js installs to your system PATH automatically.
If you already have Node installed, skip this step entirely. The version shown in the video is from 2018, and a newer version is fine. The aws-sdk methods used throughout this tutorial work across Node versions going back many years. After installation, open your terminal and run node -v. A version number confirms it is on your PATH and ready to execute JavaScript files.
Step 2: Initialize NPM in Your Project Folder
Create a folder for this project on your machine. Open that folder in your terminal. Then run npm init. NPM will ask you a series of questions: package name, version, description, entry point, and a few others. For a learning project, just press Enter through every single prompt. You can fill those fields in properly later for production code.
This generates a file called package.json in your folder. Run ls after init and you will see it. Open it up and at this stage it is a small JSON object with mostly empty or default values, because you have not installed anything yet. As you add npm packages, they get recorded under the dependencies key in this file. Think of package.json as the ledger for your project’s dependencies.
Step 3: Install aws-sdk and uuid
You need two npm packages for this tutorial. Install them one at a time. First, go to npmjs.com and search for aws-sdk. Click the package result, find the install command on the page, and copy it. The command is npm i aws-sdk. Paste it into your terminal and run it. This takes longer than most package installs because aws-sdk is large. It covers all of AWS, not just S3.
Next, search npmjs.com for uuid. Find and run the install command: npm i uuid. The uuid package generates a random string of letters, numbers, and dashes. You need it because S3 bucket names must be globally unique across all of AWS worldwide. There can never be two buckets with the same name anywhere in AWS worldwide, not just within your account. Using uuid as part of every bucket name makes collisions essentially impossible.
After both installs, open package.json again. You will now see aws-sdk and uuid listed under dependencies with their version numbers pinned. A folder called node_modules also appeared in your project directory. Never edit anything inside node_modules. That folder belongs to npm. Modifying it manually creates problems that are hard to debug, and running npm install again will overwrite your changes anyway.
Step 4: Create Your JavaScript File and Require the Modules
Open your text editor (Atom is used in the video, but VS Code, Sublime, or any other editor works). Create a new file called basic.js. Save it inside the same project folder where you ran npm init, at the same level as package.json. Your folder should now contain three things: package.json, the node_modules directory, and basic.js.
At the top of basic.js, add the two require statements that load your installed packages into the file:
var AWS = require(‘aws-sdk’);
var uuidv4 = require(‘uuid’);
The require() function pulls the module out of node_modules and makes it available in your file. The parentheses after require are mandatory. If you omit them, Node will throw an error when you try to run the file. The variable name AWS is uppercase by convention to match how the SDK expects to be referenced in method calls throughout the rest of the file.
Step 5: Configure Your AWS Credentials in Code
After the require statements, add the configuration block that tells the SDK which AWS account to use and which region to operate in:
AWS.config.update({ region: ‘us-east-1’, accessKeyId: ‘YOUR_ACCESS_KEY_ID’, secretAccessKey: ‘YOUR_SECRET_ACCESS_KEY’ });
Replace the placeholder strings with your actual values. The video uses us-east-1 as the region. Use whichever region is appropriate for your account or closest to your users. The commas separating the three properties inside the object are required. Missing a comma produces a syntax error when you try to run the file.
Your access key ID and secret access key come from the IAM service in the AWS console. Go to IAM, find your user, open the Security Credentials tab, and generate access keys. AWS prompts you to download the keys as a CSV file immediately after creation. Save that file. The secret access key is only shown once. If you lose it, you cannot retrieve it again. You have to delete the key and generate a new one.
One hard limit to know: AWS allows a maximum of two active access keys per IAM user at any time. If you try to generate a third key and AWS blocks you, log into the IAM console, find your user, and delete one of the existing two active keys before creating a new one. This limit is enforced at the IAM level and cannot be changed.
After the config block, instantiate the S3 service client with this line:
var s3 = new AWS.S3();
The uppercase AWS here references the variable you required at the top of the file. Calling new AWS.S3() creates an S3 client instance that inherits the credentials and region from the config you just set. All subsequent S3 method calls happen on this s3 variable.
Step 6: List All Your S3 Buckets
The first SDK operation to test is listBuckets, which is a good sanity check that your credentials are working correctly. Add this code below the s3 variable:
s3.listBuckets(function(err, data) { if (err) { console.log(err, err.stack); } else { console.log(data); } });
Save basic.js. Go to your terminal and run node basic.js. You must type the word node before the filename every time you run it. Typing just basic.js will not work. If your credentials and region are correct, the terminal prints a list of all S3 buckets in your account along with each bucket’s creation date. This output is identical to what you see in the AWS console or from the CLI command aws s3 ls, but now you are pulling it from inside Node.js code.
In the video, Alston’s account has twelve buckets at this point. That number will be different for your account. The important thing is that data prints without an error. If err fires instead, double-check that your access key ID and secret access key were copied correctly and that the IAM user has S3 permissions attached.
Step 7: Create a New Bucket with a Unique Name
Comment out the listBuckets call so it does not run during bucket creation testing. Then add a variable for the bucket name using uuid:
var bucketName = ‘myname’ + uuidv4.v4();
The uuidv4.v4() call generates a random string like “9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d”. Concatenating it with a readable prefix gives you a bucket name that will never collide with anything else in AWS. Bucket names must be all lowercase and cannot contain underscores. Everything in the params object you pass to SDK methods is case-sensitive, so type these property names exactly as shown.
Then add the createBucket call:
s3.createBucket({ Bucket: bucketName }, function(err, data) { if (err) { console.log(err); } else { console.log(data); } });
The Bucket key inside the params object is capitalized. Run node basic.js. A successful response prints a location string to the terminal. You can also verify visually by opening the S3 console in your browser and refreshing. The new bucket appears at the top of the list.
Step 8: Put an Object Into the Bucket
Uploading an object to S3 requires three things in your params: the Bucket name, a Key (the filename the object will have in S3), and a Body (the content of the file). The body can be any string, a Buffer, or a readable stream. For this example, it is a simple HTML string:
var objectParams = { Bucket: bucketName, Key: ‘testfile.html’, Body: ‘Hello Alston’ };
Then call putObject with those params:
s3.putObject(objectParams, function(err, data) { if (err) { console.log(err); } else { console.log(data); } });
The method name is putObject. Not createObject. This is the specific mistake the video shows in real time. Alston types s3.createObject, runs it, and gets back “s3.createObject is not a function.” That method does not exist in the SDK. The correct method is putObject. It is easy to guess the wrong name here because “create” feels more natural than “put” for uploading a new file. Remember it is putObject.
After fixing to putObject and running node basic.js, the terminal prints a response object that contains an ETag field. The ETag is the unique identifier for that object within S3. Seeing an ETag in the response confirms the upload succeeded. No ETag means something went wrong, so check the error output.
Step 9: List Objects Inside a Specific Bucket
To see what files are stored inside a particular bucket, use listObjects. Set up a params object that specifies the bucket you want to inspect and pass it to the call:
var params = { Bucket: ‘alston-test-bucket-1992’ };
s3.listObjects(params, function(err, data) { if (err) { console.log(err); } else { console.log(data); } });
The output includes every object stored in that bucket: the Key (filename), size in bytes, the last modified timestamp, and the storage class. In the video, the alston-test-bucket-1992 bucket contains an index.html file, and the SDK response shows exactly that. To confirm, Alston opens the AWS console and navigates to that same bucket where the identical file appears. Both views show the same data, which is the point. The SDK gives you programmatic access to the same information the console displays visually.
Step 10: Delete a Bucket
Deleting a bucket follows the same pattern as listing objects. Set up a params object with the Bucket key pointing to the bucket you want to remove and call deleteBucket:
var params = { Bucket: ‘alston-test-bucket-1992’ };
s3.deleteBucket(params, function(err, data) { if (err) { console.log(err); } else { console.log(data); } });
A successful delete returns empty curly braces in the terminal. That is AWS confirming the operation worked with nothing additional to report. To double-check, comment out deleteBucket, uncomment listBuckets, save, and run node basic.js again. The deleted bucket will no longer appear in the list. In the video, the count drops from 14 buckets down to 13 after the delete runs, which confirms the bucket is gone.
One important restriction: you cannot delete a bucket that still contains objects. If you try, AWS returns an error saying the bucket is not empty. You must delete all objects inside the bucket first before deleteBucket will succeed. For production use cases, you would loop through the objects using listObjects and delete each one with deleteObject before calling deleteBucket on the now-empty bucket.
Not sure which cloud or coding skill gives you the fastest path to your first $3,000 online?
Answer five questions and get a personalized match at finder.platformproof.com.
Complete Setup Checklist
- Download and install Node.js from nodejs.org, confirm with node -v
- Create a project folder, cd into it, run npm init and press Enter through all prompts
- Run npm i aws-sdk, wait for the full download to complete
- Run npm i uuid
- Create basic.js in the project folder and add var AWS = require(‘aws-sdk’) and var uuidv4 = require(‘uuid’)
- Add AWS.config.update with your region, accessKeyId, and secretAccessKey from IAM
- Add var s3 = new AWS.S3()
- Test with s3.listBuckets and run node basic.js to confirm credentials work
- Build out createBucket, putObject, listObjects, and deleteBucket calls one at a time
- Verify each operation in the AWS console by refreshing after each node basic.js run
Honest Drawbacks of This Approach
Hardcoding access keys directly in your JavaScript file is fine for learning but a serious problem for production. If that file ever gets pushed to a public GitHub repository, your keys are exposed and anyone who finds them can rack up charges on your AWS account. The production pattern is to use environment variables or the AWS credentials file (~/.aws/credentials) so the keys never appear in your source code.
The callback-based pattern shown here (function(err, data)) works, but the aws-sdk has since added Promise support and the newer AWS SDK v3 for JavaScript is organized into modular clients, meaning you only install the specific service package you need rather than the entire SDK. For new projects, looking at the v3 SDK is worth the extra setup time. The fundamentals of how S3 operations work remain the same.
UUID v4 names prevent bucket name collisions but they make buckets hard to identify at a glance. For real applications, a better pattern is to combine a meaningful prefix with the user ID or account ID from your database and a short hash. That way the bucket name is both unique and human-readable when you browse the console.
Find Your X
AWS and Node.js skills open up freelance opportunities in backend development, cloud architecture, and automated file management systems. If you want to figure out which specific skill combination gives you the fastest path to your first $3,000 online, finder.platformproof.com matches your existing background to the highest-value starting point available to you right now.
Frequently Asked Questions
What is the aws-sdk npm package?
The aws-sdk npm package is the official JavaScript library published by Amazon that lets your Node.js code communicate with AWS services. It covers the full catalog of Amazon services, not just S3, which is why it is a large package. You install it once per project and then require() whichever service you need inside your code.
Do I need a paid AWS account to follow this tutorial?
You need an AWS account, but you do not need to pay anything upfront. AWS has a free tier that covers S3 usage up to a limit each month. Creating and deleting a handful of test buckets and objects as shown in this tutorial falls well within the free tier limits. Just remember to delete your test buckets when you are done so they do not accumulate objects that count against your monthly allowance.
Why does bucket creation use the uuid package?
S3 bucket names must be globally unique across all of AWS worldwide. That means no two accounts anywhere in Amazon’s infrastructure can have a bucket with the same name. If you try to create a bucket with a name that already exists in someone else’s account, the call will fail. Appending a uuid v4 string to your bucket name makes collisions essentially impossible because the uuid is randomly generated from a space of 2 to the 122nd power possible values.
What is the difference between the SDK, the CLI, and the console?
The console is the browser-based visual interface at aws.amazon.com. The CLI is the aws command line tool you run in your terminal for scripted one-off operations. The SDK is a library you install inside your application code so that your application itself can interact with AWS at runtime based on events like a user signing up or uploading a file. Use the console for exploration, the CLI for ops scripts, and the SDK for application integration.
Why did s3.createObject fail in the video?
The createObject method does not exist in the aws-sdk. The correct method for uploading a file or object to an S3 bucket is putObject. The naming is easy to get wrong because “create” feels intuitive for adding a new file. The SDK’s terminology is “put” for uploading objects, which aligns with the HTTP PUT verb used in the underlying API call. Always use s3.putObject when uploading content to a bucket.
How do I handle errors from SDK calls?
Every SDK callback receives two arguments: err and data. If err is not null, something went wrong. You can log err directly to the console to see the error code and message. Common errors include NoSuchBucket (the bucket name you specified does not exist), AccessDenied (your IAM user lacks the required S3 permissions), and InvalidAccessKeyId (the key ID you entered is wrong or the key has been deleted). Fix the root cause rather than retrying automatically.
Can I delete a bucket that has files in it?
No. S3 requires a bucket to be empty before it can be deleted. If you call deleteBucket on a bucket that still has objects inside, the SDK returns a BucketNotEmpty error. To delete a populated bucket programmatically, first call listObjects to get all object keys, then call deleteObject or deleteObjects for each key in the list, and finally call deleteBucket once the bucket is empty. Some tools and libraries have a “force delete” wrapper that does this automatically.
Is it safe to store access keys in my JavaScript file?
For local testing and learning only. Never commit access keys to a git repository or push them to GitHub. Anyone who finds your keys in a public repo can use them to create resources in your AWS account, and the charges can be significant. For any code that will be shared or deployed, store credentials in environment variables or in the ~/.aws/credentials file on your machine, and reference them with AWS.config.update using process.env.AWS_ACCESS_KEY_ID rather than hardcoded strings.
Read Next
Once your Node.js code can create and manage S3 buckets, the next thing you will need is a properly configured IAM user with the right permissions. If you generate access keys for a root account or a user with too-broad permissions, you are creating a security risk. The following post covers how to create IAM users, set their passwords, and manage their access keys from the terminal.
AWS IAM CLI Tutorial: Create Users, Set Passwords, and Manage Access Keys
Sources
- Video: aws sdk node getting started example (2018), Mastering AWS S3 series, YouTube
- AWS SDK for JavaScript documentation: aws-sdk npm package
- npmjs.com: aws-sdk package page
- npmjs.com: uuid package page
- AWS IAM documentation: Managing access keys for IAM users
- AWS S3 documentation: Bucket naming rules
Related Reading
- Affiliate Marketing for Beginners: The Honest Guide to Getting Started
- AWS CLI IAM User Commands: Create, Manage, and Delete Users From the Terminal
- AWS SQS SDK with Node.js: A Complete Beginner Tutorial
- How To Delete A Skool Community
Helping 1 million working adults make their first $3,000 online with the skills they already have. Alston Godbolt, Platform Proof.