Resume to continue the certification exam preparation AWS Dev: AWS Lambda environment variables

The use of environment variables Lambda function, you can set dynamically passed to the function code and libraries, without any code changes. Environment variables that you use AWS Lambda Console, AWS Lambda CLI or AWS Lambda Development Kit to create as part of the function and modify the configuration key value pairs. AWS Lambda will then use the appropriate language supported by the standard API (such as for Node.js function of  process.env these key value for Lambda functions available to your code.

You can use environment variables to help libraries to know the following information: the installation files, storage location of output, storage connectivity and logging settings. These settings only by separating the application logic, when you need to change the appropriate settings based on different function behavior will not need to update your function code.

Set up

Let's say you want a Lambda function to make different behavior when subjected to different life-cycle stages from development to deployment. For example, development, test and production phases may contain a database function to be connected, and connection information of the different databases and needs to use a different table name. You can create an environment variable to refer to the relevant database name, table name or connection information, and set the value of the function depending on the stage (for example, development, test and production) the corresponding function is being executed, and your function code will remain the same.

The screenshot below shows you how to use the AWS console to modify the configuration functions. The first screen shot shows how to configure the settings corresponding to the test for a function. Second screen shot shows how to configure the settings corresponding to the function of the production stage.

Guess you like

Origin www.cnblogs.com/cloudrivers/p/11617136.html