🌐
npm
npmjs.com › package › @aws-sdk › client-s3
aws-sdk/client-s3
3 days ago - AWS SDK for JavaScript S3 Client for Node.js, Browser and React Native. Latest version: 3.1029.0, last published: 3 days ago. Start using @aws-sdk/client-s3 in your project by running `npm i @aws-sdk/client-s3`. There are 5910 other projects in the npm registry using @aws-sdk/client-s3.
      » npm install @aws-sdk/client-s3
    
Published   Apr 10, 2026
Version   3.1029.0
Discussions

amazon s3 - Is this a safe way to use aws-sdk on client side? - Stack Overflow
I have read different opinions so I'd like expert ones. My question is basic: If I create a react app (only client side), from where I'm planning to read a s3 object, is the following a safe approa... More on stackoverflow.com
🌐 stackoverflow.com
Safe way to use aws-sdk lib on client side
Never trust the client-side! If the client side is the one making the connection to your private S3 bucket, then your credentials are also available for the client so that is not a secure way to do it. Your use case allows for all users of the app to access the file, so why don't you make your S3 bucket publically accessible either through Cloudfront or directly? More on reddit.com
🌐 r/aws
11
2
March 8, 2024
amazon web services - How to set credentials in AWS SDK v3 JavaScript? - Stack Overflow
I was able to use this pattern ... with the aws js-sdk v3. 2023-12-11T16:13:03.283Z+00:00 ... This answer is basically the same as what's been said above, but for anyone who's migrating from v2 to v3 and not moving to the new modular model, you will find that your existing clients don't immediately ... More on stackoverflow.com
🌐 stackoverflow.com
How dose AWS manages all of their SDKs?
Principal Engineer for the AWS SDKs here. 1.) we have an internal service framework that has a well defined IDL. It’s mostly xml based. This is used for generating service stubs for service developers and also generates some clients that we use internally. 2.) the public SDKs have different runtime and auth requirements than internal clients. So, for the public SDKs we transform the xml based models into a Json file. You can see these in some of the GitHub repos. For example, they’re right here for the Aws SDK for c++: https://github.com/aws/aws-sdk-cpp/tree/master/code-generation This usually happens as part of the build of the service team’s code-base into our internal build system, but as serverless has become more common some service teams maintain these models separately. 3.) each SDK generates from these models. 4.) as we’ve tried to scale this format and infrastructure, we found the need to improve the idl and build infrastructure. We have a new IDL and code-gen infrastructure called “Smithy” which SDKs are in the process of moving towards. 5.) when a service team wants to launch a new feature, or a new service all together, they use an internal tool that runs a series of linters and goes through an API review. Once that’s approved and it’s release time, that system sends out a model diff through a series of pipelines to each SDK’s CD pipeline, which kicks off a code gen build, runs validation, publishes to GitHub, and pushes to package managers. It’s almost entirely automated unless the service update requires changes to code generators or the core capabilities of the SDK. Hope this helps! More on reddit.com
🌐 r/aws
34
31
January 27, 2021
🌐
GitHub
github.com › aws › aws-sdk-js-v3 › blob › main › supplemental-docs › CLIENTS.md
aws-sdk-js-v3/supplemental-docs/CLIENTS.md at main · aws/aws-sdk-js-v3
As a refresher, the basic usage of an SDK Client is of this form, using Amazon S3 as an example: // Example: sending a command (tree-shaking compatible). import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3"; const s3Client = new S3Client({}); await s3Client.send( new GetObjectCommand({ Bucket: "", Key: "", }) );
Author   aws
🌐
AWS
docs.aws.amazon.com › javascript sdk › developer guide for sdk v2 › working with services in the sdk for javascript › creating and calling service objects
Creating and Calling Service Objects - AWS SDK for JavaScript
require('aws-sdk/clients/SERVICE'); Here is what the code to create the previous Amazon S3 service object looks like when it includes only the Amazon S3 portion of the SDK.
🌐
AWS
docs.aws.amazon.com › aws sdk for java › developer guide for version 1.x › using the aws sdk for java › creating service clients
Creating Service Clients - AWS SDK for Java 1.x
Each AWS service has a service interface with methods for each action in the service API. For example, the service interface for DynamoDB is named AmazonDynamoDBClient. Each service interface has a corresponding client builder you can use to construct an implementation of the service interface.
Find elsewhere
🌐
Reddit
reddit.com › r/aws › safe way to use aws-sdk lib on client side
r/aws on Reddit: Safe way to use aws-sdk lib on client side
March 8, 2024 -

I have read different opinions so I'd like expert ones. My question is basic:
If I create a react app (only client side), from where I'm planning to read a s3 object, is the following a safe approach or my credentials will be somehow exposed? My env variable would only be stored in Netlify.

I'm asking this because I had a similar setup and my AWS was compromised (but I'm unsure if this approach was the reason).

aws-exports.js

import { config } from 'aws-sdk'
const AWSConfig = {
    accessKeyId: process.env.REACT_APP_AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.REACT_APP_AWS_SECRET_ACCESS_KEY,
    region: process.env.REACT_APP_AWS_REGION,
}
config.update(AWSConfig)

s3.js

import { S3 } from 'aws-sdk'

class S3Singleton {
    static instance = undefined
static async getInstance() {        
        if (S3Singleton.instance) {
            return S3Singleton.instance
        }
        S3Singleton.instance = await S3Singleton.createInstance()
        return S3Singleton.instance
    }
static createInstance = async () => {
        return new S3({
            apiVersion: process.env.REACT_APP_AWS_API_VERSION,
            region: process.env.REACT_APP_AWS_REGION,
            params: { Bucket: process.env.REACT_APP_AWS_BUCKET },
        })
    }
}
export default S3Singleton

The s3 object reading

import S3Singleton from './s3'

export const getXFile = async () => {
  try {
    const s3 = await S3Singleton.getInstance()

    return await new Promise((resolve, reject) => {
      s3.getObject(
        {
          Bucket: process.env.REACT_APP_BUCKET,
          Key: "xfile.json",
        },
        (err, data) => {
          if (err) reject(err)
          if (data) resolve(JSON.parse(data.Body.toString()))
        },
      )
    })
  } catch (e) {
    console.log(e)
  }
}

Top answer
1 of 4
65

There is a credential chain that provides credentials to your API calls from the SDK https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html

Loaded from AWS Identity and Access Management (IAM) roles for Amazon EC2

Loaded from the shared credentials file (~/.aws/credentials)

Loaded from environment variables

Loaded from a JSON file on disk

Other credential-provider classes provided by the JavaScript SDK

You can embed the credential inside your source code but it's not the prefered way

new S3Client(configuration: S3ClientConfig): S3Client

Where S3ClientConfig contain a credentials property

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/modules/credentials.html

    const { S3Client,GetObjectCommand } = require("@aws-sdk/client-s3");
    
    let client = new S3Client({
        region:'ap-southeast-1',
        credentials:{
            accessKeyId:'',
            secretAccessKey:''
        }
    });
    
    (async () => {
      const response = await client.send(new GetObjectCommand({Bucket:"BucketNameHere",Key:"ObjectNameHere"}));
      console.log(response);
    })();

Sample answer

  '$metadata': {
    httpStatusCode: 200,
    requestId: undefined,
    extendedRequestId: '7kwrFkEp3lEnLU+OtxjrgdmS6gQmvPdbnqqR7I8P/rdFrUPBkdKYPYykWivuHPXCF1IHgjCIbe8=',
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
2 of 4
13

Here's a simple approach I use (in Deno) for testing (in case you don't want to go the signedUrl approach and just let the SDK do the heavy lifting for you):

import { config as env } from 'https://deno.land/x/dotenv/mod.ts' // https://github.com/pietvanzoen/deno-dotenv
import { S3Client, ListObjectsV2Command } from 'https://cdn.skypack.dev/@aws-sdk/client-s3' // https://github.com/aws/aws-sdk-js-v3

const {AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY} = env()

// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/modules/credentials.html
const credentials = {
    accessKeyId: AWS_ACCESS_KEY_ID,
    secretAccessKey: AWS_SECRET_ACCESS_KEY,
}

// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html
const config = {
    region: 'ap-southeast-1',
    credentials,
}

// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/classes/s3client.html
const client = new S3Client(config)

export async function list() {
    // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/listobjectsv2commandinput.html
    const input = {
        Bucket: 'BucketNameHere'
    }

    // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/classes/command.html
    const cmd = new ListObjectsV2Command(input)
    
    // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/classes/listobjectsv2command.html
    return await client.send(cmd)
}
🌐
npm
npmjs.com › package › aws-sdk-client-mock
aws-sdk-client-mock - npm
The AWS SDK for JavaScript version 3, is the new version of SDK to use in Node.js and browser. It comes with modular architecture and improved typing, thanks to being written in TypeScript. The recommended way of using it is to create a Client and use it to send Commands.
      » npm install aws-sdk-client-mock
    
Published   Oct 15, 2024
Version   4.1.0
Author   Maciej Radzikowski
🌐
AWS
docs.aws.amazon.com › aws sdk for javascript › developer guide for sdk version 3 › work with aws services in the sdk for javascript › create service client requests
Create service client requests - AWS SDK for JavaScript
Call send on the client with the command object as input. For example, to list your Amazon DynamoDB tables in us-west-2, you can do it with async/await. import { DynamoDBClient, ListTablesCommand } from "@aws-sdk/client-dynamodb"; (async function () { const dbClient = new DynamoDBClient({ region: 'us-west-2' }); const command = new ListTablesCommand({}); try { const results = await dbClient.send(command); console.log(results.TableNames.join('\n')); } catch (err) { console.error(err); } })();