In this video we are going to learn how to use a lambda environment variables.
Amongst variables, very important topics that we can use with the lambda functions.
We can use variables to adjust our functions behavior without updating the code.
An environment variable is a pair of strings that is stored in a function's version specific configuration.
So it is lambda runtime makes environment variables available to our code and set additional environment
variables that contain information about the function and the invocation of the request.
So we can configure environment variables with using a case management console.
Let me show from the management console first.
Go to functions, go to my function three and if you click the configuration, we can set the environment
variables to set and one with variable.
Go to lambda console, open the function page, choose the function, choose the configuration and choose
the environment variables.
Here you can see the materials under the environment variables, we can choose the edit button and we
can add the environment variable in here.
For example, let me add an environment variable.
The key could be the table name and table name will be the product.
Okay.
This will be the ah first environment variable for mind function three.
Let me save here.
You can see that we can add environment variable B using the management console and also we can configure
in one service with Lambda API or a CDK, SLI or SDHC.
So let me show you one example about a SLI.
Please open the OR.
We used to decode and create a Neve folder structure and open the command text file.
You can see in here there's an example about how we can configure a mime to use with using the SQL Command,
a lambda update function configuration and giving the function name and set the environment variables
in here.
So let me copy these lines and paste in here and hit enter.
This will be edit or configuration and we can verify from the these configurations in here.
Let me refresh this page.
And see that the bucket employment variables is added in here and also key and final text value will
be added or configurations.
But you should be careful about that when ah, when we are performing the update function configuration,
this is overriding our previous employment variables.
So that's why we can add again the table name and table name is product.
You should careful about that.
Okay, very good.
So we have seen how we can configure our environment variables with using the same commands.
When you apply implement variable with the update function configuration command, the entire context
of the variable structure is replaced in order to retain existing employment variables.
When you add a new one, include all the existing in your values.
In the request of these CLI or HDC commands, we can also get the current configuration in order to
get the current configurations, use the get function configuration.
You can see in this command a lambda get function configuration.
This will be provide to get all configurations for us.
Of course this will be my function three.
Let's see how we can.
It's all complications from the environment variables.
If you hit the answer, you can see that this time we can see the environment variables.
We have three minus variable table name, bucket and key.
So we can retrieve environment variables with this way, but also we can retrieve these values into
our lambda function code.
This is a very powerful feature that we don't need to change code with using the environment variables.
For example, I think that the table name information could be changed and you can only change the environment
variable without touching any code line.
So how we can retrieve these values in lambda function, you can see example in here.
This is the an example, an example lambda function that we can get environment variables from the process
that envy that the environment variable for example, a region table name and so on.
This will be provided to get a variable in programmatically from the lambda functions and we are using
the environment variable function in it.
So this is the way how we can grab the environment variables in lambda function without touching any
code we can change the table name from the event variables and the code will be reflect with newest
and with variable.
As you can see that we have seen how to use a lambda employment variables.