【问题标题】:Pass enviromental variable on the fly to Serverless invoke local function即时将环境变量传递给无服务器调用本地函数
【发布时间】:2022-01-14 22:08:59
【问题描述】:

我有以下无服务器配置文件:

service: aws-node-scheduled-cron-project

frameworkVersion: '2 || 3'

plugins:
  - serverless-plugin-typescript

provider:
  name: aws
  runtime: nodejs14.x
  lambdaHashingVersion: 20201221
  region: us-west-2
  # Imports all the enviromental variables in `.env.yml` file
  environment: ${file(./env.yml)}

functions:
  ...

env.yml

DATABASE_HOST: 127.0.0.1
DATABASE_USER: root
DATABASE_PASSWORD: your_mysql_root_password
DATABASE_TABLE: laravel
DATABASE_PORT: 3306
DATABASE_USE_SSL: false
NOTIFICATION_SERVICE_URL: http://localhost:4000

现在我想在本地调用函数时即时更改DATABASE_TABLE。我试过了:

export DATABASE_TABLE=1-30-task-template-schedule && npx serverless invoke local --function notifyTodoScheduleFullDay

但变量DATABASE_TABLEenv.yml 中的变量覆盖。可以通过命令行来实现吗?

【问题讨论】:

    标签: node.js amazon-web-services shell serverless-framework


    【解决方案1】:

    在您的yml 文件中,您可以将表名声明为${opt:tablename,'DEFAULT'}。 这一行意味着您将在终端命令中将名称作为参数提供,例如serverless deploy ... -tablename NAME_OF_THE_TABLE,如果您不将其作为参数提供,则它采用您可以提供的默认名称。这可以即时生成名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-18
      • 1970-01-01
      • 2017-06-21
      • 2019-02-14
      • 2021-06-25
      • 2013-12-29
      • 2019-06-02
      • 2021-12-15
      相关资源
      最近更新 更多