Skip to content

Latest commit

 

History

History
112 lines (73 loc) · 4.42 KB

File metadata and controls

112 lines (73 loc) · 4.42 KB

Invoking, Listing, and Deleting Lambda Functions

This section provides examples of programming with the Lambda service client by using the AWS SDK for Java 2.0.

You can invoke a Lambda function by creating a :aws-java-class:`LambdaClient <services/lambda/LambdaClient>` object and invoking its :methodname:`invoke` method. Create an :aws-java-class:`InvokeRequest <services/lambda/model/InvokeRequest>` object to specify additional information such as the function name and the payload to pass to the Lambda function. Function names appear as arn:aws:lambda:us-west-2:555556330391:function:HelloFunction. You can retrieve the value by looking at the function in the AWS Console.

To pass payload data to a function, create a :aws-java-class:`SdkBytes <core/SdkBytes>` object that contains information. For example, in the following code example, notice the JSON data passed to the Lambda function.

Imports

.. literalinclude:: lambda.java2.invoke.import.txt
   :language: java

Code

The following code example demonstrates how to invoke a Lambda function.

.. literalinclude:: lambda.java2.invoke.main.txt
   :dedent: 4
   :language: java

See the complete example on Github.

Build a :aws-java-class:`LambdaClient <services/lambda/LambdaClient>` object and invoke its :methodname:`listFunctions` method. This method returns a :aws-java-class:`ListFunctionsResponse <services/lambda/model/ListFunctionsResponse>` object. You can invoke this object's :methodname:`functions` method to return a list of :aws-java-class:`FunctionConfiguration <services/lambda/model/FunctionConfiguration>` objects. You can iterate through the list to retrieve information about the functions. For example, the following Java code example shows how to get each function name.

Imports

.. literalinclude:: lambda.java2.list.import.txt
   :language: java

Code

The following Java code example demonstrates how to retrieve a list of function names.

.. literalinclude:: lambda.java2.list.main.txt
   :dedent: 4
   :language: java

See the complete example on Github.

Build a :aws-java-class:`LambdaClient <services/lambda/LambdaClient>` object and invoke its :methodname:`deleteFunction` method. Create a :aws-java-class:`DeleteFunctionRequest <services/lambda/model/DeleteFunctionRequest>` object and pass it to the :methodname:`deleteFunction` method. This object contains information such as the name of the function to delete. Function names appear as arn:aws:lambda:us-west-2:555556330391:function:HelloFunction. You can retrieve the value by looking at the function in the AWS Console.

Imports

.. literalinclude:: lambda.java2.delete.import.txt
   :language: java

Code

The following Java code demonstrates how to delete a Lambda function.

.. literalinclude:: lambda.java2.delete.main.txt
   :dedent: 4
   :language: java

See the complete example on Github.