Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Environment variable file path

Case 1: If the user provided an environment variable file path. ( e.g.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." ]

...

  • 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 withlambda-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.

...

Case 1: If the user provided an Artifact file path. (e.g. 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 withlambda-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:"

...

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

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. For below file the path provided can be : give example

...

Extracted zip file:

...

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. [ to get the environment file path, we are using this method ( String envVariableFilePath = getEnvVariableFilePath(); )

And in this method, we are considering all the scenarios to get the variable file path once we get the file path we are passing the path to get the function name ( String functionName = deriveLambdaFunctionNameFromProjectPropertyOrFileName(envVariableFilePath); ) ] So in this way we are checking for the below-mentioned scenarios as well.

  1. What if the file itelf is present in Artifact dir

  2. What if the file is present inside a zip file inside Artifact dir

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:

...

So in this case we are not checking for File name right? Update the error msg.. stating atleast one of the values is needed.

Will update the message from ( throw new FlexCheckedException(AWSProperties.FDAWS_LAMBDA_00025_FAILED_TO_RETRIVE_FUNCTION_NAME, "Failed to retrieve the function name."); ) to

( throw new FlexCheckedException(AWSProperties.FDAWS_LAMBDA_00025_FAILED_TO_RETRIVE_FUNCTION_NAME, "Failed to retrieve the function name, Either function name or Environment variable file path is needed."); )

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.

    • Remember to remove the version.. can we extract image name easily from url? Consider version could be latest as well [ ok, sure. Yes we can easily get the function name from the image ]

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.

    • S3 key is basically the file name inside bucket right? [ yes, right. It is a distinctive identifier for an object stored in a bucket. ]

  • If Both ECR/S3 option is not given then check if name of the local archive path is not empty, then extract the file name and use it as function name.

  • Here we don’t need to throw the exception because one of the above cases will always satisfy. [ As we are already doing the check while getting the deployment type.]

  • Options not provided for local file type [ Added option ]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 ]

...