serverless-s3-sync icon indicating copy to clipboard operation
serverless-s3-sync copied to clipboard

Support syncing single file

Open Horgix opened this issue 5 years ago • 5 comments

Feature request - Support syncing single file

Need

I would like to use this plugin to sync a single local file to an S3 bucket created by Serverless. However, this plugin only supports syncing directories, as stated in the description.

Would you be open to extending this plugin so it can also sync simple files?

Contribution

I've already modified it on my side to make it work and am wondering if I could contribute it back.

Implementation

The main question is regarding the breaking change possibility.

While it is possible to just handle single file with its path passed through the current localDir parameter, it isn't really logical for users to path a file to something called localDir imho.

To avoid that, it would be possible to rename this field into localPath but it would then be a breaking change. It's also possible to introduce a new parameter called localFile which would be mutually exclusive with localDir, but that adds more conditional logic to the code.

What do you think about all of this? I'm ready to send a PR with whatever will be needed.

Horgix avatar Mar 13 '19 16:03 Horgix

Howdy @Horgix @k1LoW What is the status of this issue? This feature will be useful also for me ;) Could @Horgix send this PR? I think localDir can be reused for single files too (only mention this in docs).

programmer04 avatar Aug 14 '19 09:08 programmer04

@Horgix sorry for too late repry 🙏

localPath is good idea !

I think

  • create localPath that allow dir and single files.
  • show deprecation message if using localDir

k1LoW avatar Aug 15 '19 13:08 k1LoW

@k1LoW @Horgix I've just found myself needing this very feature, it looks like this might have been forgotten about over the last couple of years, is there any chance of seeing this come to fruition at all or if not would you be willing to share your amendments and/or publish a forked version of it @Horgix

Regards

Chris

cmjchrisjones avatar Jan 12 '23 23:01 cmjchrisjones

In the meantime a workaround that I have found is thus:

given I only want to sync a single file (in my case index.html), move it into a src folder

in the serverless.yml file, update the custom section and the WebsiteConfiguration.IndexDocument like so:

custom:
  siteName: <your-site-name>
  s3Sync:
    - bucketName: ${self:custom.siteName}
      localDir: src/

resources:
  Resources:
    StaticSite:
      Type: AWS::S3::Bucket
      Properties:
        AccessControl: PublicRead
        BucketName: ${self:custom.siteName}
        WebsiteConfiguration:
          IndexDocument: ./src/index.html

cmjchrisjones avatar Jan 15 '23 22:01 cmjchrisjones

Hey @k1LoW, I investigated the feature, and IMO requires a recursive implementation on the given path. I want to utilize it as a plugin to upload a single file or directory. It needs to detect the type of given path and consider the process to perform.

Appreciate any thoughts or input.

msudgh avatar Jul 15 '23 20:07 msudgh