- Setting Environment variables docs used
There are two places where you’ll need to set environment variables: development-time and deployment-time. To do this, open the launchSettings.json file from under the Properties folder in the Solution Explorer. Then add the following JSON property:
"environmentVariables": {
"my-api": "something"
}
To set environment variables at deployment-time, you can add these to the aws-lambda-tools-defaults.json file. (Just remember to escape the double quote marks.)
environment-variables, its format is: "<key1>=<value1>;<key2>=<value2>;".
In your case you should have
"environment-variables" : "\"my-api\"=\"http://myapihost.com/api/attendance-backfill\";"
Consuming/fetching the environment variables
Consuming the environment variables as part of the Lambda function’s logic is done intuitively in the C# code, by using the System library aws blog:
System.Environment.GetEnvironmentVariable(<key>);
In your case you can use the following;
var apiUrl = System.Environment.GetEnvironmentVariable("my-api");
In this document it is suggested that your approach for fetching environment variable is correct.
var variableValue = Environment.GetEnvironmentVariable("nameOfVariable");