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

serverless-plugin-deploy-environment

v2.1.0

Published

Plugin the augments the serverless provider environment with deployment variables

Downloads

48

Readme

serverless-plugin-deploy-environment

serverless Coverage Status Build Status

This plugin exposes per-stage deployment variables and deployment environment, and allows users to run commands with the environment of a given stage. The defined deployment environment is automatically merged with the serverless provider environment. It also optionally resolves credstash variables. The benefit of this is that its simpler to manage different variables for each environment, and makes the addition of default environment variables simple.

See our docs for full documentation.

Usage

Basic Usage

provider:
  region: us-west-2
custom:
  deploy:
    variables:
      dev:
        role: "devRole"
        streamArn: "devStream"
      staging:
        role: "stagingRole"
        streamArn: "stagingStream"
    environments:
      # These will be added to all environments
      default:
        LAMBDA_LOG_LEVEL: info
        LAMBDA_REGION: ${self:provider.region} # All references are resolved
        LAMBDA_ES_HOST:
          'Fn::GetAtt': [ 'ESCluster', 'DomainEndpoint' ]
      dev:
        LAMBDA_ES_HOST: localhost

plugins:
  - serverless-plugin-deploy-environment

Given this config, running with sls deploy --stage dev would yield the following resolved configuration

deployVariables:
  role: "devRole"
  streamArn: "devStream"
deployEnvironment:
  LAMBDA_LOG_LEVEL: info
  LAMBDA_REGION: us-west-2
  LAMBDA_ES_HOST: localhost

Running in an Environment

This plugin also exposes a command to run with the stage environment exposed. Give the above config, the command sls runWithEnvironment --command 'echo $LAMBDA_ES_HOST' --stage 'dev' will output localhost.

Production Usage

The way that we use this at Doppler is that we have two separate configuration files at config/deploy.yml and config/variables.yml. All of the variables defined in deploy.yml will become environment variables, and everything in variables.yml are internal variables used to resolve references elsewhere in serverless.yml. Then, in our main serverless.yml file, we have

custom:
  deploy:
    variables: ${file(config/variables.yml)}
    environments: ${file(config/deploy.yml)}

provider:
  # ... Other static properties
  domain: ${self:deployVariables.domain}
  role: ${self:deployVariables.role}

Credstash

This plugin also offers the ability to resolve credstash secrets anywhere in the Serverless configuration. First, set up credstash by following the instructions here. Then, in your configuration file, you can add:

custom:
  deploy:
    environments:
      staging:
        MY_PASSWORD: ${credstash:stagingPassword}
      production:
        MY_PASSWORD: ${credstash:productionPassword}

Please note that because these are resolved at build time, the plain-text passwords WILL be viewable in Cloudformation and on the Lambda dashboard.

Version History

  • 2.1.0
    • Fix merge mutation issue (Thanks @onhate!)
  • 2.0.2
    • Fix CLI warning (Thanks @onhate!)
  • 2.0.1
    • Dependency security updates
  • 2.0.0
    • Require a more modern version of node and remove the old babel runtime dependency.
  • 1.2.0
    • Allow default stage population for variables (Thanks @FluxAugur!)
  • 1.1.0
    • Change invocation target, to play nicely with other offline plugins (like serverless-offline-sns)
  • 1.0.3
    • Fix packaging issue
  • 1.0.2
    • Bump version of credstash to deal with change in API (Thanks @concon121)
  • 1.0.1
    • Fix publishing issue
  • 1.0.0
    • Initial release