Code Engine
IBM Cloud Code Engine is a fully managed, serverless platform that runs your containerized workloads, including web apps, micro-services, event-driven functions, or batch jobs. Code Engine represents a service destination, where an incoming notification can be consumed programmatically. For example, an incoming notification about an event can trigger a Code Engine destination to a backend microservice to act based on the content of the incoming notification.
Configuring a Code Engine destination
Before you configure Code Engine as a destination for run type Job, make sure that you have a Code Engine project created and job configured in the same account as your Event
Notifications instance.
If there is run type Job, if you are using Event Notifications CLI or API to configure Code Engine job as a destination, help ensure that you have enabled authorization to grant access between services. For more information, see
Using authorizations to grant access between services.
To configure a Code Engine destination, complete the following steps:
-
From your Event Notifications instance, click Destinations.
-
Click Create to add a new destination.
-
Enter the following destination details in the Create destination dialog:
- Name: Enter a name for your destination.
- Description: Optionally, enter a description for your destination.
- Type: Under Destination, select Code Engine from the list as your destination type.
- Run Type: Select one of the run type Code Engine jobs or Code Engine application.
If the selected run type is job, provide the following details:
-
Project name: Select the Code Engine project name from the list. Otherwise, click Create new project to create a Code Engine project.
When you select a Code Engine project, the authorization between the services is created internally between the two service instances, if the authorization does not exist.
-
Job name: Select the job name from the list.
If the selected run type is application, provide the following details:
- URL: Enter the Code Engine application secured URL (only HTTPS).
- Verb: Select the verb to be called (GET or POST).
- Headers: Optionally, enter a list of headers to be passed to the Code Engine application.
-
Click Create destination.
Event Notifications now supports Code Engine Functions.
Using authorizations to grant access between services
Use IBM Cloud® Identity and Access Management (IAM) to create or remove an authorization that grants one service access to another service.
Creating an authorization in the console
-
In the IBM Cloud console, click Manage > Access (IAM), and select Authorizations.
-
Click Create.
-
Select a source account.
- If the source service that needs access to the target service is in this account, select This account.
-
Select a Source service such as Event Notifications.
-
Specify whether you want the authorization to be for all resources or Resources based on selected attributes. If you have chosen Resources based on selected attributes, then specify the Add attributes: only source resource group or only source service instance.
-
Select a Target service as Code Engine.
-
For the target service, specify whether you want the authorization to be for all projects, only to a specific project in the account, or projects only in a certain resource group.
-
Select both the roles (Viewer and Writer) to assign access to the source service that accesses the target service.
If you have selected only one of these two roles (Reader or Writer) during the service to service authorization, you cannot trigger a job or configure destination. You get an error for service to service authorization failure in these cases. Make sure that you recreate an authorization between the services with both the roles selected.
-
Click Authorize.
Creating an authorization by using the CLI
To authorize a source service to access a target service, run the ibmcloud iam authorization-policy-create command.
For more information about all of the parameters that are available for this command, see ibmcloud iam authorization-policy-create.
Accessing event payload in Code Engine job
The event payload has been transmitted to Code Engine job by using an environment variable, which can be retrieved by using the ibmendata environment variable.
Testing a Code Engine destination configuration
You can test a Code Engine destination in the options menu next to the destination. You can test whether the provided configuration is correct with a single click.
For more information on testing a destination, see Testing Destinations.
Code Engine retry policy
When sending notifications to Code Engine, issues such as network errors and application glitches can cause the requests to fail. Event Notifications automatically retries failed requests to provide resiliency.
For detailed information about retry behavior, including retry attempts, delays, and timeout values, see Retry policy for destinations.