This guide shows you how to initialize an NPM package, add a service client to your package, and use the JavaScript SDK to call a service action.
- Running this code might result in charges to your AWS account. For more details, see AWS Pricing and Free Tier.
Create a new NPM package with one main file that does the following:
- Creates an Amazon Simple Storage Service (Amazon S3) bucket.
- Puts an object in the bucket.
- Reads the object.
- Confirms if the user wants to delete resources.
Before you can run the example, you must do the following:
- Configure your SDK authentication
- Install Node.js
- Create a new folder to contain the package.
- From the command line, navigate to the new folder.
- Run
npm init -y
. This creates a defaultpackage.json
file. - Add
"type": "module"
to thepackage.json
. This tells Node we're using modern ESM syntax.
The final package.json should look similar to this:
{
"name": "example-javascriptv3-get-started-node",
"version": "1.0.0",
"description": "This guide shows you how to initialize an NPM package, add a service client to your package, and use the JavaScript SDK to call a service action.",
"main": "index.js",
"scripts": {
"test": "vitest run unit"
},
"author": "Corey Pyle <corepyle@amazon.com>",
"license": "Apache-2.0",
"dependencies": {
"@aws-sdk/client-s3": "^3.420.0"
},
"type": "module"
}
- Run
npm i @aws-sdk/client-s3
.
- Refer to index.js.
node index.js
- Choose whether to empty and delete the bucket.
- If you don't delete the bucket, be sure to manually empty and delete it later.