kotlin/services/lambda/README.md
Shows how to use the AWS SDK for Kotlin to work with AWS Lambda.
<!--custom.overview.start--> <!--custom.overview.end-->Lambda allows you to run code without provisioning or managing servers.
For prerequisites, see the README in the kotlin folder.
Code examples that show you how to perform the essential operations within a service.
Code excerpts that show you how to call individual service functions.
<!--custom.examples.start--> <!--custom.examples.end-->This example shows you how to do the following:
⚠ Running tests might result in charges to your AWS account.
To find instructions for running these tests, see the README
in the kotlin folder.
You can test the Kotlin code examples for Lambda by running a test file named LambdaTest. This file uses JUnit 5 to run the JUnit tests and is located in the src/test/kotlin folder. For more information, see https://junit.org/junit5/.
You can run the JUnit tests from an IDE, such as IntelliJ, or from the command line by using Maven. As each test is run, you can view messages that inform you if the various tests succeed or fail. For example, the following message informs you that Test 3 passed.
Test 3 passed
WARNING: Running these JUnit tests manipulates real Amazon resources and may incur charges on your account.
Before running the Lambda JUnit tests, you must define values in the config.properties file located in the resources folder. This file contains values that are required to run the JUnit tests. For example, you define an function name used for various tests. If you do not define all values, the JUnit tests fail.
Define the following values to successfully run the JUnit tests:
Note: The CreateFunction and LambdaScenario tests requires a .zip or .jar file that represents the code of the Lambda function. If you do not have a .zip or .jar file, please refer to the following document:
https://github.com/aws-doc-sdk-examples/tree/master/javav2/usecases/creating_workflows_stepfunctions
To run the JUnit tests from the command line, you can use the following command.
mvn test
You will see output from the JUnit tests, as shown here.
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running LambdaTest
Test 1 passed
Test 2 passed
...
Done!
[INFO] Results:
[INFO]
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0
[INFO]
INFO] --------------------------------------------
[INFO] BUILD SUCCESS
[INFO]--------------------------------------------
[INFO] Total time: 12.003 s
[INFO] Finished at: 2020-02-10T14:25:08-05:00
[INFO] --------------------------------------------
If you do not define the correct values in the properties file, your JUnit tests are not successful. You will see an error message such as the following. You need to double-check the values that you set in the properties file and run the tests again.
[INFO]
[INFO] --------------------------------------
[INFO] BUILD FAILURE
[INFO] --------------------------------------
[INFO] Total time: 19.038 s
[INFO] Finished at: 2020-02-10T14:41:51-05:00
[INFO] ---------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project S3J2Project: There are test failures.
[ERROR];
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0