🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

serverless-exports-plugin

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serverless-exports-plugin

Serverless Framework plugin to export Environment variables and CloudFormation outputs to a file

1.3.1
latest
Source
npm
Version published
Weekly downloads
561
78.66%
Maintainers
0
Weekly downloads
 
Created
Source

CI npm npm

Serverless Exports Plugin

This plugin exports environment variables and stack outputs from your Serverless project to local files. These files can then be used in development or in CI/CD pipelines to set environment variables or use as input for other tools.

Terminal

Usage

Install the plugin as a development dependency in your Serverless project:

npm install --save-dev serverless-exports-plugin

Then add the plugin to your serverless.yml file:

plugins:
  - serverless-exports-plugin

Finally, configure the exports you want to generate:

custom:
  exports:
    environment:
      file: .env.${sls:stage}
      format: env 
      overwrite: true
    stack:
      file: stack-outputs.txt
      format: env
      overwrite: true

That's it! Now you can run serverless deploy or serverless package or serverless info and the plugin will generate the exports for you.

Configuration

The plugin supports two type of exports: environment variables and stack outputs.

The configuration for each export is the following:

custom:
  exports:
    <environment | stack>:
      file: path/to/file
      format: env | yaml # not implemented yet: json | toml
      overwrite: true | false

Only exports that are configured will be generated. There are no default values, so if you want to generate an export you need to configure it.

Example

The plugin runs during serverless deploy, serverless package and serverless info commands. However, the stack outputs are only available after the stack has been deployed. Therefore, the plugin will only generate the stack outputs during serverless deploy.

service: acme-service
frameworkVersion: '3'

plugins:
  - serverless-exports-plugin

custom:
  exports:
    environment:
      file: .env.${sls:stage}
      format: env
      overwrite: true    
    stack:
      file: stack-outputs.txt
      format: env
      overwrite: true    

provider:
  name: aws
  runtime: nodejs18.x
  environment:
    FOO: bar
    STAGE: ${sls:stage}
    REGION: ${sls:region}
    SERVICE: ${self:service}

functions:
  hello:
    handler: index.handler

resources:
  Resources:
    bucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${self:service}-${sls:stage}-bucket
  Outputs:
    Foo:
      Value: bar
    BucketName:
      Value: !Ref bucket

Deploy

$ serverless deploy

Deploying acme-service to stage dev (us-east-1)

✔ Exported environment variables to .serverless/.env.dev
  FOO: bar
  STAGE: dev
  REGION: us-east-1
  SERVICE: acme-service

✔ Exported stack outputs to .serverless/stack-outputs.txt
  ServerlessDeploymentBucketName: acme-service-dev-serverlessdeploymentbuck-a242ab89
  HelloLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-1:000000000000:function:acme-service-dev-hello:1
  Foo: bar
  BucketName: acme-service-dev-bucket

✔ Service deployed to stack acme-service-dev (12s)

functions:
  hello: acme-service-dev-hello (66 kB)

Package

$ serverless package

Packaging acme-service for stage dev (us-east-1)

✔ Exported environment variables to .serverless/.env.dev
  FOO: bar
  STAGE: dev
  REGION: us-east-1
  SERVICE: acme-service

✔ Service packaged (1s)  

Info

$ serverless info

✔ Exported environment variables to .serverless/.env.dev
  FOO: bar
  STAGE: dev
  REGION: us-east-1
  SERVICE: acme-service

service: acme-service
stage: dev
region: us-east-1
stack: acme-service-dev
functions:
  hello: acme-service-dev-hello

Open Points

  • Support for different export formats (env, json, toml, yaml)
  • Support for a JavaScript handler function to process the exports
  • Collect function-level environment variables and merge with global environment variables
  • Support for include/exclude patterns for variables and outputs
  • Export stack outputs when running serverless package and serverless info, if the stack has already been deployed
  • Serverless command severless exports to generate the exports without deploying the stack

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Keywords

serverless

FAQs

Package last updated on 08 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts