1.0.0-rc.6 • Published 10 months ago

sync-cloud-storage v1.0.0-rc.6

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

sync-cloud-storage

NPM Pipeline Status Codecov Status License

sync-cloud-storage is a Node.js package designed to seamlessly synchronize files and directories between local environments and cloud storage providers like AWS S3. It leverages AWS SAM (Serverless) and AWS Cloud Development Kit (CDK) for powerful, modern, and flexible integrations.

Features

  • Sync multiple storage at once
  • Use pattern matching on finding files (single or multiple file/dir sync) by defining patterns of glob to include or exclude
  • Supports a set of options as following for each file based on storage features: Prefix, Access Control List (ACL), Tags, Metadata
  • Modern and uses the latest official cloud provider's SDK

Installation

  • npm: npm i sync-cloud-storage
  • yarn: yarn add sync-cloud-storage
  • pnpm: pnpm add sync-cloud-storage
  • ni: ni sync-cloud-storage

Usage

AWS S3

Serverless

The integration is powered by Serverless hooks and In below, the default configured hooks are listed:

  • scs:storages -> As a CLI command for serverless
  • scs:tags -> As a CLI command for serverless
  • scs:metadata -> As a CLI command for serverless
  • before:offline:start:init -> Sync storages (scs:storages)
  • before:deploy:deploy -> Sync storages (scs:storages)
Example

This setup uses before:deploy:deploy hook to sync storages before deploying the stack:

plugins:
  - sync-cloud-storage

custom:
  syncCloudStorage:
    - name: my-bucket
      patterns:
        - assets/*
      actions:
        - upload
        - delete
      prefix: assets
      acl: public-read
      metadata:
        foo: bar
        bar: foo
      tags:
        foo: bar
        bar: foo

CDK

Call storages action to sync after setting up a CDK App and Stack:

import { Stack, App } from '@aws-cdk/core'
import SyncCloudStorage from 'sync-cloud-storage'

const app = new App()
const stack = new Stack(app, 'MyStack')
const syncCloudStorage = new SyncCloudStorage(stack, {
  storages: [
    {
      name: 'my-bucket',
      patterns: ['assets/*'],
      actions: ['upload', 'delete'],
      prefix: 'assets',
      acl: 'public-read',
      metadata: {
        foo: 'bar',
        bar: 'foo',
      },
    },
  ],
})

syncCloudStorage.storages()

Options

General

OptionNotesTypeRequiredDefault
storagesList of storages, Minimum items: 1array of storagetrueundefined
regionCloud (AWS) regionstringfalseundefined or AWS_REGION environment variable
endpointCloud (AWS) Endpoint URLstringfalseundefined or AWS_ENDPOINT_URL environment variable
offlineOffline modebooleanfalsefalse or IS_OFFLINE environment variable
disabledDisable syncbooleanfalsefalse
silentSilent output logsbooleanfalsefalse

Storage

OptionNotesTypeRequiredDefault
nameName of storage (AWS S3 Bucket), Minimum length: 1stringtrueundefined
patternsPatterns of glob paths to include or exclude on sync action, Minimum items: 1array of stringtrueundefined
actionsSync actions, Valid values: upload, deletearray of stringfalseupload: Only upload new or modified file, delete: Only delete files that are not in the local environment from the storage
prefixPrefix for the storage files and foldersstringfalse''
enabledEnable or disable the storage on sync actionbooleanfalsetrue
aclAWS S3 Canned ACL, Valid values: private, public-read, public-read-write, authenticated-readstringfalseundefined
metadataA set of metadata key/value pair to be set or unset on the objectobjectfalseundefined
tagsA set of tag key/value pair to be set or unset on the objectobjectfalseundefined
gitignoreUse .gitignore file to exclude files and directoriesbooleanfalsefalse
ignoreFilesIgnore files and directories to exclude from sync actionarray of stringfalseundefined