...
AWS Lambda environment variables use are used to adjust the function's behavior without updating the code. An environment variable is a key-value pair of strings that are is stored in a function's version-specific configuration. Lambda runtime makes environment variables available to our code and sets additional environment variables that contain information about the function and invocation request. We are going to use the addLambdaEnvironmentVariables operation of the FlexDeploy AWS Plugin to add the Lambda function environment variables. We can use the file or Input Argument input argument to add the environment variables and the operation also supports encryption of the variables using AWS KMS key. We can select the option to publish a new version, but by default the operation will not publish the a new version. The operation will use the configured AWS cloud account to perform the operation.
Objective
The goal of the this tutorial is to add the environment variables , using the environment file present at the git repository and input argument, and also publish the function version. We will also add secured variables, and to encrypt these variables we are going to use the AWS KMS key. We will have a project property added in the deploy workflow and this project property value will contain the list of the environment variables that we are going to use in the workflow input. We can use the dynamic value in both the environment file and input argument, please refer to the this document to get more details about environment variables' acceptable structure.
...
: AWS Lambda Environment Variables Accepted Structure. These are the general steps we’ll follow:
Configuring the properties e.g. Cloud account , and CLI path.
cloning Cloning the environment file from a Git repository.
adding Adding the environment variables to the Lamba function.
sample Sample code to retrieve the value of secured environment variables.
Checklist
Checklist | Description |
AWS Access Key | AWS Access Key of the user. |
AWS Secret Key | Password for the Access Key |
AWS Default Region | Default region can be set. eg. ap-south-1 |
AWS CLI installation | AWS CLI needs to be installed where the plugin operation shall run (FlexDeploy server) |
AWS CLI in class path | AWS CLI should be added to the class path on the FlexDeploy Server. Else the path can also be set under FlexDeploy environment level property |
AWS Lambda Function | AWS Lambda Function should be already present. |
AWS KMS Key | AWS KMS key to secured the environment variable. |
...
Build and Deploy Workflows
Navigate to the Workflows tab and create a workflow using the “+”(Click to create new Workflow) button as highlighted below.
...
Next, create Create one Build and Deploy workflow as shown below. The workflow Type field defines the type of one Deploy workflow.
Build Workflow
Navigate to the Workflows
Select the “+” button from the left-hand pane to create a new workflow
...
Deploy Workflow
navigate to the Workflows
Select the “+” button from the left-hand pane to create a new workflow
...
The Workflow Group and Subgroup define the folder hierarchy. Once both workflows are created it should look like the below. No constraint on workflow or folder naming convention.
...
The steps of the workflow execution can be configured through the Workflow Definition section.
...
Below given is Below given is a sample build workflow to copy the file from Git repository.
...
Step-ii: Copy the environment file
The below step will copy the environment file to the artifact. Also artifacts directory. Make sure to check the Produces Artifact option to save the files as artifact so that can be used from Deploy workflow.
...
Deploy Workflow
Below given is a sample deploy workflow to add the environment variable to the AWS Lambda function.
...
This step will add environment variables to the Lambda Function and publish the version.
...
In above configuration using following InputsThe above step has the following inputs.
Input Name | Input Code | Type | Required | Description |
Additional Arguments | FDAWS_LAMBDA_INP_ADD_ENV_VAR_ADDITIONAL_ARG | String | No | Literal key and value pairs. e.g. --region=us-east-1 --memory-size=512 --timeout=33 And for boolean type arguments give the option without any value. e.g --publish --debug |
Environment Variables | FDAWS_LAMBDA_INP_ENV_VAR | String | No | Environment Variables in acceptable format. |
Publish new version | FDAWS_LAMBDA_INP_PUBLISH_VERSION | Boolean | No | Select to publish a new version. Default value is false. |
Project Configuration
Navigate to the Project tab and create a Project with a logical name(AWS-Lambda-Environment-Variable in this case)
...