GithubHelp home page GithubHelp logo

serverless-plugin-scripts's Introduction

serverless-plugin-scripts npm version

Add scripting capabilities to the Serverless Framework.

Caution

This project is in maintenance mode, and it will not get any new features.

Installation

Install the plugin in your Serverless (v1.0 or higher) project:

npm install --save serverless-plugin-scripts

And activate it by adding the following configuration to your serverless.yml file:

plugins:
  - serverless-plugin-scripts

Usage

Custom commands

To add a custom command to the Serverless CLI, just define a custom.scripts.commands property in your serverless.yml file:

custom:
  scripts:
    commands:
      hello: echo Hello from ${self:service} service!

You can now run serverless hello to execute the hello command.

Simple hooks

It is possible to define simple hooks for existing Serverless CLI commands by adding a custom.scripts.hooks property in your serverless.yml file:

custom:
  scripts:
    hooks:
      'deploy:createDeploymentArtifacts': npm run compile

The next time you run serverless deploy, your script will be automatically invoked during the deploy:createDeploymentArtifacts lifecycle event.

To find out about existing lifecycle events, check out this page.

Author

Created and maintained by Manuel Vila.

License

MIT

serverless-plugin-scripts's People

Contributors

mvila avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

serverless-plugin-scripts's Issues

Multiple commands for each hook

This plugin is very useful, and it would be even more so if we are able to execute multiple commands for each serverless hook.

inject stack outputs to script?

how would you inject the output of your cloudformation stack, e.g. ServiceEndpoint, to a build script for post processing? e.g. to dynamically inject the api endpoint into your frontend

"deploy:finalize" hook do not recognise the stage when passed as a command line argument

I know this project is in maintenance rather than active development; I am submitting this in the hope that bug fixes are still being implemented.


I am using hooks to run a function after I deploy my application.

custom:
  scripts:
    hooks:
       "deploy:finalize": serverless invoke -f runAfterDeploy

I run serverless deploy and specify the stage with the --stage option. The problem is that the above hook / function call does not seem to recognise whatever it is that I have specified as the stage. If I have set stage using the following serverless.yml config so that it uses whatever is supplied via the --stage parameter:

provider:
  name: aws
  runtime: nodejs12.x
  stage: ${opt:stage}

...then I get the following error when I deploy using serverless deploy --stage prod. The deploy runs correctly and the prod value is used everywhere, but the hook does not recognise it and has undefined as the value:

https://i.imgur.com/ruaaA06.png

This is a major headache if the runAfterDeploy task does something important. Using ${self:opt, "dev"} instead produces a similar result, whereby no matter what you specify via --stage the variable always ends up being "dev".


Here's the full re-producible serverless.yml:

service: serverless-demo

frameworkVersion: "2"

plugins:
  - serverless-offline
  - serverless-plugin-scripts

custom:
  scripts:
    hooks:
       "deploy:finalize": serverless invoke -f runAfterDeploy

provider:
  name: aws
  runtime: nodejs12.x
  region: eu-west-1
  stage: ${opt:stage}
  environment:
    stage: ${self:provider.stage}

functions:
  runAfterDeploy:
    handler: handler.runAfterDeploy
    events:
      - http:
          path: /runAfterDeploy
          method: get
          cors: true

Feature request: Add ability to specify script configuration with variables

Add ability to specify script configuration node as any sls variable.

Example:

custom:
  scripts: ${file(./your/path/config-hooks.yml)}

Proposal:
Add configuration value population in configuration load method getConfig()

Current state:

  getConfig() {
    const service = this.serverless.service;
    return service.custom && service.custom.scripts;
  }

Change proposition:

  getConfig() {
    const service = this.serverless.service;
    const config = service.custom && service.custom.scripts;
    if (config) {
       return this.serverless.variables.populateValue(config);
    }
    return undefined;
  }

Scripts whitespace removed in new serverless versions

Since serverless 1.27.0, the scripts ran by this plugin have all whitespace removed.

i.e.

  deploy:
      finalise: >
          cp -rf public/favicon.ico dist &&
          aws s3 sync dist s3://some-url

runs

cp-rfpublic/favicon.icodist&&awss3syncdists3://some-url

Passing ENV variables

Hello,

In my serverless.yml, there are many env variables that I want to pass to the command that I have defined which is:

scripts:
    commands:
      nosetests: nosetests

so if I run sls nosetests, it throws an exception stating that env vars are not defined..
How can I solve it? or is there any other solution to run nosetests with env variables?

Thanks :D

Lifecycle Events Documentation

I went to the serverless website but can't seem to find the documentation for the different life cycle events. Do you know what the event is for after a resource is created in serverless, like say an RDS Database Instance etc or S3 Bucket. I want to run the script after those have been confirmed to be created successfully.

Commands no longer working with SLS v1.59.2

I took the example right out of the docs, and I get:

Serverless command "hello" not found. Did you mean "deploy"? Run "serverless help" for a list of all available commands.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.