This example illustrates how to write a service in NodeJS
that listens for events and sends an automated email to the address in the event payload.
- A Docker installation
- Kyma as the target deployment environment
- An environment to which to deploy the example
-
Build the Docker image
docker build . -t event-email-service:latest
-
Run the recently built image
docker run -p 3000:3000 event-email-service:latest
-
Export your environment as a variable by replacing the
<environment>
placeholder in the following command and running it:export KYMA_EXAMPLE_ENV="<environment>"
-
Deploy the service
kubectl apply -f deployment -n $KYMA_EXAMPLE_ENV
-
Expose the service endpoint
kubectl port-forward -n $KYMA_EXAMPLE_ENV $(kubectl get pod -n $KYMA_EXAMPLE_ENV -l example=event-email-service | grep event-email-service | awk '{print $1}') 3000
To test the service, simulate an event via cURL:
curl -H "Content-Type: application/json" -d '{"event":{"customer":{"customerID": "1234", "uid": "[email protected]"}}}' http://localhost:3000/v1/events/register
After sending the event, you should see a log entry either in your terminal (if running locally) or in the Pod's logs (if running on Kyma) confirming the event reception.
Clean all deployed example resources from Kyma with the following command:
kubectl delete deployment,svc -l example=event-email-service -n $KYMA_EXAMPLE_ENV