Code Monkey home page Code Monkey logo

serverless-plugin-local-env's Introduction

serverless-plugin-local-env

This plugin is used to resolve AWS resources in the debugger environment variables when using the serverless framework.

Use case

When debugging with serverless framework, resources created and referenced as part of the framework will often resolve to "[object object]". This makes debugging with serverless framework very difficult as reproducing the lambda environment must then be done with command line attributes.

This plugin will connect with your AWS Stack and its resources in order to resolve "Ref", "Fn::GetAtt" and "Fn::ImportValue" statements when setting up your environment variables for local debugging.

Implementing

Install the plugin into the directory your serverless.yml is located

npm install @moe-tech/serverless-plugin-local-env

Add the plugin to your serverless yaml plugins

plugins:
    - "@moe-tech/serverless-plugin-local-env"

Invoke your function

serverless invoke local --function {Function Name}

Cache

In order to improve performance this plugin creates a cache of resources references. This cache is automatically cleared out when a new deployment occurs, but can also be manually cleared by deleting the ".serverless/invoke.cache.json" file.

Example

The example provided is a serverless project which contains a DynamoDB Table, an SNS Topic, an SQS Queue, a Lambda Function and it exports a value.

Steps:

  1. navigate to the example directory in the console "./example"
  2. install dependencies
    npm ci
  3. deploy the serverless project
    serverless deploy
  4. Un-comment lines #21 & #22 in the serverless.yml file
  5. Invoke the function to run locally
    serverless invoke local --function hello
    or
    npm start
  6. View the console logs which are printed

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.