The AWS SDK for JavaScript v3 modular packages (@aws-sdk/client-s3, etc.) integrate with Node.js servers and Lambda handlers using async/await.
Install modular client
npm install @aws-sdk/client-s3
export AWS_PROFILE=sandbox
export AWS_REGION=us-east-1
List buckets
import { S3Client, ListBucketsCommand } from '@aws-sdk/client-s3';
const client = new S3Client({ region: 'us-east-1' });
const out = await client.send(new ListBucketsCommand({}));
console.log(out.Buckets?.map(b => b.Name));Practice: Run SDK examples locally with sandbox credentials via AWS_PROFILE=sandbox. Never commit real keys—use IAM roles in deployed environments.
Lambda handler pattern
export const handler = async (event) => {
// IAM execution role grants permissions
return { statusCode: 200, body: JSON.stringify({ ok: true }) };
};
Best practices
- Import only clients you need—smaller Lambda bundles
- Reuse client outside handler in Lambda for connection reuse
- Use AWS SDK middleware for logging and retries consciously
Important interview questions and answers
- Q: SDK v3 vs v2?
A: v3 is modular with command pattern; smaller tree-shaken bundles for Lambda. - Q: Why reuse S3Client in Lambda?
A: Avoids creating new clients per invocation—faster warm starts.
Self-check
- What npm package lists S3 buckets in SDK v3?
- Why avoid access keys in Node.js source code?
Tip: Import only @aws-sdk/client-* packages you need to shrink Lambda bundles.
Interview prep
- SDK v3 modularity?
Import @aws-sdk/client-* packages for smaller Lambda bundles.
- Reuse client?
Create S3Client outside handler in Lambda for warm invocation efficiency.