AWS Lambda - Environment Variable File and zip File location options

Environment variable file path

Case 1: If the user provided an environment variable file path.

Consider this path as an example: ( lambda-demo/EnvironmentFile/lambda-demo.json )

First, operation will perform validation on a given variable file path, we are throwing an exception if the file extension is not present. [ FDAWS_LAMBDA_00021_ADD_ENV_INVALID_FILE_PATH, "Invalid file path is given, the file extension is not present." ]

After validation, operation will perform following steps to get file.

  • Consider the given path as an absolute path and check if a file exists on the given path.

  • If the file does not exist on the given path, then consider the path as a relative path and check the file in the Artifact directory. ( $FD_ARTIFACT_DIR/lambda-demo/EnvironmentFile/lambda-demo.json )

  • If no file is found using the above option, then check if the file is present under the temp Directory.

It can happen the file is present inside a zip file residing under the artifact folder(result of Consume Artifact). The plugin first extracts the content of the zip file under the temp directory. Then it will search the file pattern inside the temp File. (Any file path under $FD_TEMP_DIR ending with lambda-demo/EnvironmentFile/lambda-demo.json )

Note: While doing the pattern match for the file, in case more than one file is found then we are throwing the exception with the message: More than one environment Variable file present.

After performing above steps if we are not getting the file then we are throwing the exception. [ FDAWS_LAMBDA_00020_ADD_ENV_VARIABLE_FILE_NOT_FOUND, "File is not present on the given path: " + pGivenFilePath ]

Case 2: If no file path is given or the value of the file path is “NA”

Printing the message: LOG.logInfo(methodName, "Environment variable file path not provided or file path value is set as NA"); and continue the execution and check the input argument for environment variables.

Artifact File Path ( Applicable only for local archive )

Case 1: If the user provided an Artifact file path.

Consider this path as an example: ( lambda-demo/FunctionCode/lambda-demo.zip )

  • Consider the given path as an absolute path and check if an Artifact file exists on the given path.

  • If the file does not exist on the given path, then consider the path as a relative path and check the file in the Artifact directory. ( $FD_ARTIFACT_DIR/lambda-demo/FunctionCode/lambda-demo.zip )

  • If no file is found using the above option, then check if the file is present under the temp Directory.

It can happen that the zip file (to update function code ) is present inside a zip file present under the artifact folder. The plugin first extracts the content of the zip file under the temp directory. Then it will search the File pattern inside the temp File. (Any file path under $FD_TEMP_DIR ending with lambda-demo/FunctionCode/lambda-demo.zip )

After performing the above steps if we don’t get the file on the given path then we are throwing an exception, with the error message: "No zip file is found on given path:"

Case 2: If the user is not provided a path

If the user is not provided a path, then we are searching the Artifact directory for the file with the ‘zip’ extension and using that file to deploy the lambda function. In case more than one file is present we are throwing an exception.

Note. For both the Environmental variable file path and Artifact File Path user can use a variable value to give the path.

e.g. ${{FD_ARTIFACTS_DIR}}/lambda-demo/FunctionCode/lambda-demo.zip

${{FD_ARTIFACTS_DIR}}/lambda-demo/EnvironmentFile/lambda-demo.json

Example of Artifact directory file structure

Example-1: Here we have both environment file and function code in our Artifact directory.

Example-2: Users can also give a single Artifact file that contains both the Environment file and the zip file to update the function code. Just need to provide the right path pattern.

Here we have the Environment file and Function code, we have to give the file path for both the Environment variable and Artifact.

Environment variable file path: EnvironmentFile/lambda-demo.json

Artifact file path: FunctionCode/lambda-demo.zip

Extracted zip file:

Function Name ( Add environment variable operation )

[ Priority : user-provided function name > extract name of the file from the env file path and use it as function name ]

  • If the user provided the function name, then use that value as a priority.

  • If the user not giving the function name, then consider the name of the environment variable file as the function name.

If the function name and environment variable file path both are not given in that case, we are throwing an exception with the error message: "Failed to retrieve the function name."

Function Name ( Update function code operation )

[ Priority : user-provided function name > ECR image name > S3 key name > extract file name from local archive path ]

  • If the user provided the function name, then use that value as a priority.

  • If the ECR option is given, then use the image name as the function name.

Example of url: "898334718399.dkr.ecr.us-east-1.amazonaws.com/lambda:1.0" ( here function name will be lambda )

  • If the ECR option is not given then check S3 option and if it’s given, then use the name of the S3 key as the function name.

  • If Both ECR/S3 option is not given then name of the local archive fill be use as function name.

Deployment Type

  • If the Amazon ECR option is given, then give priority to ECR. [ deploymentType = ECR ]

  • If ECR URL detail is not given then check S3 details, in case of S3, both the bucket name and the key name are required, in case one of the bucket/key name is missing then throw an exception with the error message: "To update the function code using S3, both S3 Bucket and S3 key name are required." [ deploymentType = S3 ]

  • If ECR/S3 detail is not given, then by default deployment type is set to local. [ deploymentType = LOCAL ]

 

The following macros are not currently supported in the footer:
  • style