This example shows how to bind lambda functions to a service. A lambda function connects to a Redis instance and retrieves statistics for this service.
The example covers these tasks:
- Create a Redis instance.
- Create a function using Kubeless CLI.
- Bind the function to the Redis Service.
- Call the lambda function.
- Install the Kubeless CLI as described in the Kubeless installation guide.
Apply a battery of yaml files to run the example.
-
Export your environment as variable by replacing the
<environment>
placeholder in the following command and running it:export KYMA_EXAMPLE_ENV="<environment>"
-
Create a Redis instance and a service binding to the instance.
kubectl apply -f deployment/redis-instance.yaml,deployment/redis-instance-binding.yaml -n $KYMA_EXAMPLE_ENV
-
Ensure that the Redis instance and Redis binding service are provisioned.
kubectl get serviceinstance/redis-instance -o jsonpath='{ .status.conditions[0].reason }' -n $KYMA_EXAMPLE_ENV kubectl get servicebinding/redis-instance-binding -o jsonpath='{ .status.conditions[0].reason }' -n $KYMA_EXAMPLE_ENV
-
Create a lambda function as Redis client.
kubectl apply -f deployment/lambda-function.yaml -n $KYMA_EXAMPLE_ENV
-
Create a ServiceBindingUsage resource.
kubectl apply -f deployment/service-binding-usage.yaml -n $KYMA_EXAMPLE_ENV
-
Verify that the lambda function is ready.
kubeless function ls redis-client -n $KYMA_EXAMPLE_ENV
-
Trigger the function. The information and statistics about the Redis server appear in the logs of the function Pod.
kubeless function call redis-client -n $KYMA_EXAMPLE_ENV
Use this command to remove the example and all its resources from your Kyma cluster:
kubectl delete all,function,servicebinding,serviceinstance,servicebindingusage -l example=service-binding -n $KYMA_EXAMPLE_ENV
Make sure the password is injected correctly into the Pod. The password should match the one in the redis-instance.yaml
kubectl exec -n $KYMA_EXAMPLE_ENV -it $(kubectl get po -n $KYMA_EXAMPLE_ENV -l example=service-binding --no-headers | awk '{print $1}') bash
env | grep -i redis_password