Connect Service to Component
What you’ll learn
How to connect your component to a Managed service (e.g., database, authentication service, messaging service, etc.) or an External service.
The main advantage of doing so within CodeNOW is that you don't have to worry about connection credentials in order to create and use Managed services, all it takes is a few clicks. Therefore, you, as a developer, have everything you need at your disposal.
Prerequisites
- Choose the existing application or Create a New Application
- Create a New Application Component
- Create a New Managed Service or an External service
How to create a new connection to Managed or External service
While creating a new component
- Click on the Add new connection button
- Choose a name for the connection and select one of the supported services
- Click Confirm
This adds the newly defined connection to the .codenow.config.yaml
file in the main branch.
Editing an existing component
- Go to the
Connected Services
section in the detail of your component - Select the branch for which you want to add a new service connection and click on the Edit button
- Click on the Add connection button
- Choose a name for the connection and select one of the supported services
- Click Confirm
How to configure Runtime Connectivity
- Find Connected Services in component detail and click on the Connection properties button
- The displayed environment variables will be set during deployment depending on which service instance you choose to use
- Modify your project's deployment configuration to use the environment variables from the previous step for establishing a connection with the service
- The format of your configuration files depend on your tech stack
- For example, for the PostgreSQL from the images below, you could define the following connection string:
"Host=${POSTGRESQL_HOST};Port=${POSTGRESQL_PORT};Database=${POSTGRESQL_DATABASE_NAME};User Id=${POSTGRESQL_USERNAME};Password=${POSTGRESQL_PASSWORD}"
info
Select a specific service instance in preview or manually created deployment configuration and CodeNow will automatically set the environment variables, so that your component will be connected to the chosen service.