All skills
aws avatar

/aws-sdk-js-v3-usage

@c3ed514

AWS SDK for JavaScript v3 development patterns. Use when writing JavaScript or TypeScript code that uses AWS services via @aws-sdk/* packages (aws-sdk-js-v3), or when asked about schemas, runtime validation, serialization, or code generation in the context of the JS/TS AWS SDK.

Use this Skill: https://skilld.dev/gh/aws/agent-toolkit-for-aws/aws-sdk-js-v3-usage

This session only. Nothing lands on disk.

referenceseffective-practices.md

≈577 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Effective Practices Reference

Client Reuse

Create one client per region+credentials combination. Don't create clients inside loops:

// WRONG:
for (const item of items) {
  const client = new S3Client({ region, credentials });
  await client.send(new PutObjectCommand(item));
}

// OK:
const client = new S3Client({ region, credentials });
for (const item of items) {
  await client.send(new PutObjectCommand(item));
}

Don't Read or Mutate client.config

client.config is a resolved form — region becomes async () => "us-east-1", credentials are wrapped, etc. Reading or writing it directly will cause errors:

// WRONG: — throws "config.region is not a function"
client.config.region = "us-west-2";

// WRONG: — throws "client.config.endpoint is not a function"
const endpoint = await client.config.endpoint();

To use multiple regions, create separate clients (share credentials to avoid duplicate resolution):

import { fromTemporaryCredentials } from "@aws-sdk/credential-providers";
const creds = fromTemporaryCredentials({ params: { RoleArn: "..." } });
const east = new S3Client({ region: "us-east-1", credentials: creds });
const west = new S3Client({ region: "us-west-2", credentials: creds });

To get the resolved endpoint for a specific operation:

import { getEndpointFromInstructions } from "@smithy/middleware-endpoint";
const endpoint = await getEndpointFromInstructions(
  { Bucket, Key },
  GetObjectCommand,
  { region: "us-west-2", useDualstackEndpoint: false, useFipsEndpoint: false }
);
console.log(endpoint.url.toString());

Always Read or Discard Streaming Responses

Unread streams hold sockets open → socket exhaustion / memory leak:

const { Body } = await client.send(new GetObjectCommand({ Bucket, Key }));

// OK: read
const bytes = await Body.transformToByteArray();

// OK: pipe
await client.send(new PutObjectCommand({ Bucket: dest, Key, Body }));

// OK: discard
await (Body.destroy?.() ?? Body.cancel?.());

// WRONG: — socket stays open
// (no action on Body)

Cross-Region Connection Timeouts (Node.js 20+)

For cross-region requests that hit ETIMEDOUT / AggregateError:

import net from "node:net";
net.setDefaultAutoSelectFamilyAttemptTimeout(500); // default is 250ms

Source: SKILL.md on GitHub

No alerts17d3 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill is a comprehensive documentation resource for the AWS SDK for JavaScript v3. It provides development patterns, best practices for credential management, resource handling, and performance optimization using official AWS packages and repositories.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

Signed by skilld at c3ed514. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 5 months ago

README badge

README badge for aws/agent-toolkit-for-aws/aws-sdk-js-v3-usage