TestLambda
, Group ID is idevelop.lambda
and Artifact ID là s3handler
. Click Finish to create project.After updating the project dependencies through Maven, run JUnit Test by selecting Run As | JUnit Test.
You will see outpur result of Lambda function, as if it were triggered by a file uploaded to S3. The parameters for the test are provided in the test resource, in the JSON payload form similar to the payload that the Amazon environment will send to Lambda function, when S3 bucket associated with this Lambda function receives the uploaded file.
You may see some warnings related to the profile name.
You can ignore this warning in this exercise.
To view the output of the JUnit test, select the JUnit tab
You will probably see a warning regarding the missing node. You can safely ignore this warning.
The provided source code doesn’t take care of the encoding applied to the key name that is provided in S3 event when it is sent to Lambda function, so if you upload a file to test, and the file contains spaces or punctuation, this string needs to be decoded before use.
You can solve this problem with the following code.
5. Add the following code after line 28 in the LambdaFunctionHandler.java class in src/main/java/idevelop.lambda.s3handler:
try
{
key = java.net.URLDecoder.decode(key, "UTF-8");
}
catch(Exception ex)
{
context.getLogger().log("Could not decode URL for keyname... continuing...");
}