postlight/serverless-typescript-starter

How use with serverless-env-generator

Closed this issue · 1 comments

Hi, i'm using serverless-env-generator to protect my env variables with KMS.
But, I can't use with this boilerplate.

.enviroment.yml

production:
  INSTAGRAM_MAX_ITEMS: '6'
  YOUTUBE_MAX_ITEMS: '6'
dev:
  INSTAGRAM_MAX_ITEMS: '6'
  YOUTUBE_MAX_ITEMS: '6'
staging:
  INSTAGRAM_MAX_ITEMS: '6'
  YOUTUBE_MAX_ITEMS: '6'

serverless.yml

custom:
  webpack:
    webpackConfig: ./webpack.config.js
    packager: 'yarn'
    includeModules:
      forceExclude:
        - aws-sdk
  warmup:
    enabled: true
    events:
      - schedule: rate(5 minutes)
    prewarm: true
    concurrency: 1
  envFiles:
    - environment.yml
  envEncryptionKeyId: ${env:AWS_KMS_KEYID}

plugins:
  - serverless-env-generator
  - serverless-webpack
  - serverless-offline
  - serverless-plugin-warmup
  - serverless-dotenv-plugin

webpack.config.js

const nodeExternals = require('webpack-node-externals')
const slsw = require('serverless-webpack')
const Dotenv = require('dotenv-webpack')

module.exports = {
  entry: slsw.lib.entries,
  target: 'node',
  mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
  externals: [nodeExternals()],
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/
      },
      {
        test: /\.jsx?$/,
        include: __dirname,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader'
        }
      }
    ]
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js', '.jsx']
  },
  plugins: [
    new Dotenv()
  ]
}

lambda.js

import 'dotenv/config'
import { corsSuccessResponse, corsErrorResponse, runWarm } from '../utils'

const handler = async event => {
/* logic */
}
export default runWarm(handler)

Lambda env in console:
image

Could some one help me?

Hey @derevandal, it seems this issue is not related to the starter kit.

After looking into the documentation for serverless-env-generator, I noticed something missing in your config that might be causing this issue:

  envFiles:
    - environment.yml
  envEncryptionKeyId: ${env:AWS_KMS_KEYID} // dev is missing here (https://github.com/DieProduktMacher/serverless-env-generator#3-add-the-plugin-to-your-serverless-configuration-file)

And make sure you are creating a KMS key as mentioned in the docs