Skip to content

Fastify plugin for ensuring existence of defined s3 buckets on the application startup

License

Notifications You must be signed in to change notification settings

kibertoad/fastify-s3-buckets

Repository files navigation

fastify-s3-buckets

Fastify plugin for ensuring existence of defined AWS S3 buckets on the application startup.

NPM Version Build Status

How to use?

import fastify from 'fastify';
import { fastifyS3BucketsPlugin } from 'fastify-s3-buckets';
import { S3Client } from '@aws-sdk/client-s3'

const s3Config = {
    endpoint: 'http://s3.localhost.localstack.cloud:4566',
    region: 'eu-west-1',
    credentials: {
        accessKeyId: 'access',
        secretAccessKey: 'secret',
    },
}
const s3Client = new S3Client(s3Config)

const app = fastify()
app.register(fastifyS3BucketsPlugin, {
    s3Client,
    buckets: [
        { Bucket: 'abc', ACL: 'private' },
        { Bucket: 'def', ACL: 'public-read' },
        { Bucket: 'ghi', ACL: 'private' }
    ],
})
await app.ready() // missing buckets will be created here

Note that if buckets already exist, they will not be recreated. Existing buckets that are not specified will not be deleted.

About

Fastify plugin for ensuring existence of defined s3 buckets on the application startup

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published