npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nx-s3-plugin

v1.0.7

Published

Utilities for managing S3 with NX. Includes sync'ing local directories with remote S3 buckets.

Downloads

12

Readme

nx-s3-plugin

npm

This is an NX executor that can be used to make changes to remote S3 buckets.

Installation

Install the plugin in to your already configured NX workspace

npm i nx-s3-plugin

Executors

| Name | Description | | ---- | ----------------------------------------------------- | | sync | Synchronize a local directory with a remote S3 bucket |

sync

The sync executor is similar to the aws s3 sync command. It will run a diff between local files and files contained in S3, and make S3 reflect the local directory. This can be very performant because only files which have changed will be uploaded. Bucket name can also be dynamically looked up from existing CloudFormation exports or SSM Parameters.

Uploaded Bucket Object content-type

This plugin uses mime-types to make a best guess at file mime types as they are uploaded to S3. This means your files should arrive in S3, ready to be served as a static assets without having to manually define the types.

AWS Credentials

The standard AWS credential chain of precedence is followed when making AWS calls. @aws-sdk/credential-provider-node is used to to load these values, so that documentation should be used when setting up AWS credentials. In most cases, simply having the proper environment variables or valid credentials in your ~/.aws/credentials file should be enough to get going. There is an optional profile argument that can be used if you wish to use a non-default set of credentials.

Properties

| Name | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | sourceFiles | The path to the local files that you wish to upload. In the case of a static site, these should already be compiled (ie webpack). | | bucketName | The name of the S3 bucket where the files should be uploaded. See notes on setting this value to retrieve a CF exported value or SSM Parameter value. | | region | (Optional) The AWS region where requests will be sent. Will default to the local system default. | | profile | (Optional) The AWS credentials profile that will be used to make requests. Default system AWS credentials will be used if omitted. | | batchSize | (Optional) The number of files that will be present in each batch. Batched files are uploaded in parallel. Default is 500. | | progress | (Optional) Display upload progress. True by default. | | deleteFiles | (Optional) Should files be deleted in S3 if they are no longer present in the local directory. True by default. |

Usage

You do not need to add s3:// to bucketName, your CloudFormation export value, or your SSM parameter value. This plugin will add it for you.

Add the executor to the target section of project.json.

  "targets": {
    "upload-site": {
      "executor": "nx-s3-plugin:sync",
      "options": {
        "sourceFiles": "<source-directory>",
        "bucketName": "[cfe|ssm]:<target-bucket>",
      }
    }
  }

Static S3 Bucket Name

If you are directly targetting an S3 bucket, you can simply enter the name of the S3 bucket as the bucketName parameter in the NX task definition.

  "targets": {
    "upload-site": {
      "executor": "nx-s3-plugin:sync",
      "options": {
        "sourceFiles": "/my-compiled-website-files",
        "bucketName": "my-s3-bucket",
      }
    }
  }

Dynamic Cloudformation Export Lookup

If you prepend your bucketName with cfe:, this executor will attempt to locate a CloudFormation export with the same name. Omitting the cfe: prefix will simply use the bucketName value as is for the S3 url.

  • If an export is found with a matching name, the value will be used for the S3 destination bucket.
  • If an export is not found, an error will be thrown and no files will be uploaded.
  • Matching is case-sensitive.
  • This export must exist in the same account as the S3 bucket.
    • Cross-account lookup is not supported.

Example:

cfe:StaticWebSite will query CloudFormation for an export named StaticWebSite and use the value of that export as the bucketName.

  "targets": {
    "upload-site": {
      "executor": "nx-s3-plugin:sync",
      "options": {
        "sourceFiles": "/my-compiled-website-files",
        "bucketName": "cfe:StaticWebSite",
      }
    }
  }

Dynamic SSM Paramter Store Lookup

If you prepend your bucketName with ssm:, this executor will attempt to locate a SSM Paramter with the same name. Omitting the ssm: prefix will simply use the bucketName value as is for the S3 url.

  • If an SSM Parameter is found with a matching name, the value will be used for the S3 destination bucket.
  • If an SSM Parameter is not found, an error will be thrown and no files will be uploaded.
  • Matching is case-sensitive.
  • This SSM Parameter must exist in the same account as the S3 bucket.
    • Cross-account lookup is not supported.

Example:

ssm:/myapp/s3bucket will query for an SSM Parameter named /myapp/s3bucket and use the value of that export as the bucketName.

  "targets": {
    "upload-site": {
      "executor": "nx-s3-plugin:sync",
      "options": {
        "sourceFiles": "/my-compiled-website-files",
        "bucketName": "ssm:/myapp/s3bucket",
      }
    }
  }