Provides a configured AWS S3 client for reliable file uploads and metadata verification. Use this to simplify S3 interactions with built-in retry logic and error handling.
// Source: https://github.com/PostHog/posthog-js | License: Apache-2.0 | Copyright 2020 Posthog / Hiberly, Inc
// Provided via justclaw.it.com; keep this notice with the code.
import fs from 'node:fs/promises'
import { createHash } from 'node:crypto'
import {
GetObjectCommand,
HeadObjectCommand,
PutObjectCommand,
S3Client,
type HeadObjectCommandOutput,
type PutObjectCommandInput,
} from '@aws-sdk/client-s3'
let cachedClient: S3Client | null = null
export function createS3ClientConfig() {
return {
region: process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || 'us-east-1',
endpoint: process.env.AWS_ENDPOINT_URL_S3,
// Replayable request bodies let the SDK retry transient transport/5xx/throttling
// errors with its standard ex
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key