Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
105 lines (71 sloc) 3.77 KB

Event Bus Lambda Subscription


This example shows how to subscribe lambda functions to the Kyma Event Bus to receive Events.

Follow it to:

  1. Create a Kubeless function to handle published Events.
  2. Subscribe the created function to a topic, so that Events can activate or trigger it.
  3. Test triggering of the function by publishing Events.


  • Install the Kubeless CLI as described in the Kubeless installation guide.

  • After installing the CLI, export the name of the kubeless config configmap resource name and the namespace where it is located into the shell environment.

  • A Namespace to which to deploy the example with the env: "true" label. For more information, read the related documentation.

export KUBELESS_CONFIG=core-kubeless-config
export KUBELESS_NAMESPACE=kyma-system

To get information about currently-supported runtimes, use this command:

kubeless get-server-config


  1. Export your Namespace as a variable by replacing the {namespace} placeholder in the following command and running it:

    export KYMA_EXAMPLE_NS="{namespace}"
  2. Create a Kubeless function to receive a JSON Event.

    NOTE: The function must be able to receive POST requests.

    You can find the function file here

    Run this command:

    kubeless function deploy hello-with-data --label example=event-bus-lambda-subscription --runtime nodejs8 --handler hello-with-data.main --from-file js/hello-with-data.js -n $KYMA_EXAMPLE_NS
  3. Set your Namespace on the subscription endpoint:

    sed -i "s/<namespace>/$KYMA_EXAMPLE_NS/g" deployment/subscription.yaml
    sed -i '' "s/<namespace>/$KYMA_EXAMPLE_NS/g" deployment/subscription.yaml

    To manually edit subscription.yaml, replace the <namespace> placeholder in the endpoint with your Namespace.

  4. Subscribe the function to an Event:

    kubectl apply -f deployment/event-activation.yaml,deployment/subscription.yaml -n $KYMA_EXAMPLE_NS
  5. Test publishing Events to the subscribed function.

    • Start a sample publisher. The system creates the Publisher deployment.

      kubectl apply -f deployment/sample-publisher.yaml -n $KYMA_EXAMPLE_NS
    • Spawn a shell inside the publisher.

      kubectl exec -n $KYMA_EXAMPLE_NS $(kubectl get pods -n $KYMA_EXAMPLE_NS -l app=sample-publisher --output=jsonpath={}) -c sample-publisher -i -t -- sh
    • Publish an Event inside the publisher container.

      NOTE: The data field expects a JSON object.

      Run this command:

      curl -i \
      -H "Content-Type: application/json" \
      -X POST http://event-bus-publish.kyma-system:8080/v1/events \
      -d '{"source-id": "external-application", "event-type": "hello", "event-type-version": "v1", "event-time": "2018-11-02T22:08:41+00:00", "data": { "order-number": 123 }}'
    • Verify that tailing logs for the function Pod trigger the function:

      kubectl logs -f $(kubectl get po -n $KYMA_EXAMPLE_NS -l function=hello-with-data --no-headers | grep -i running | awk '{print $1}') -c hello-with-data -n $KYMA_EXAMPLE_NS


Run this command to remove the example and all of its resources:

kubectl delete all -l example=event-bus-lambda-subscription -n $KYMA_EXAMPLE_NS