Access environment variables in function?

When specifying environment variables in serverless.yml how do you then reference those key/values inside your function handler?

I am specifying the variables at the provider level but I do not see them on event or context inside my function handler

EDIT: I didn’t realize these were just set as Node environment variables, can access through process.env

1 Like

Following is a sample code in serverless.yml

functions:
  myFunction:
handler: handler.myFunction
environment:
  my_var_1: "val_1"
  my_var_2: "val_2"
events:
  - http:
      path : myFunction
      method : post
      cors : true

Following code will come in handler. js to use the variables

const var_1_val= process.env.my_var_1;

Ideally you should store environment variables in ec 2 parameter store and then use them in serverless.yml