Local file-based mock for AWS S3 for unit and local testing for AWS JavaScript SDK v3+.
Based on mock-aws-s3 and aws-sdk-mock.
import { createS3Client } from 'mock-aws-s3-v3';
import { GetObjectCommand } from '@aws-sdk/client-s3';
const client = createS3Client('./local-folder'); // of type S3Client
await client.send(new PutObjectCommand({
Bucket: 'test-bucket',
Key: 'test-key',
Body: 'hello',
});
This will create:
- Folder
./local-folder/test-bucket
- File
./local-folder/test-key
with content 'hello'
The following operations are currently supported in this mock:
- CreateBucketCommand
- DeleteBucketCommand
- ListObjectsCommand
- ListObjectsV2Command
- DeleteObjectsCommand
- DeleteObjectCommand
- GetObjectCommand
- HeadObjectCommand
- PutObjectCommand
- CopyObjectCommand
- GetObjectTaggingCommand
- PutObjectTaggingCommand
Same as mock-aws-s3 minus getSignedUrl
. For an example of how getSignedUrl
could be mocked, see templateS3Bucket.ts.