Error while binding service instance in SAP CAP using external service

3.8k views Asked by At

In SAP CAP, I am following this Blog example link for creating CAP project consuming an external service. However, during deployment to Clound Foundry, I encountered an error below:

Error encountered during deployment:

Updating application "external-service-srv"...
Unbinding service instance "external-service-uaa" from application "external-service-srv"...
Binding service instance "external-service-uaa" to application "external-service-srv"...
Binding service instance "external-service-destination" to application "external-service-srv"...
Error while binding service instance "external-service-destination" to application "external-service-srv": Could not bind service "external-service-destination" to application "external-service-srv": 404 Not Found: Service instance external-service-destination not found. 
Proceeding with automatic retry... (3 of 3 attempts left)

Below code snippet are my configurations:

mta.yaml

_schema-version: '3.1'
ID: external-service
version: 1.0.0
description: A simple CAP project.
parameters:
  enable-parallel-deployments: true
build-parameters:
  before-all:
    - builder: custom
      commands:
        - npm ci
        - npx -p @sap/cds-dk cds build --production
modules:
  - name: external-service-srv
    type: nodejs
    path: gen/srv
    parameters:
      buildpack: nodejs_buildpack
    build-parameters:
      builder: npm-ci
    provides:
      - name: srv-api
        properties:
          srv-url: '${default-url}'
    requires:
      - name: external-service-destination
      - name: external-service-uaa
resources:
  - name: external-service-destination
    type: org.cloudfoundry.existing-service
    parameters:
      service: destination
      service-name: external-service-destination
  - name: external-service-uaa
    type: org.cloudfoundry.managed-service
    parameters:
      path: ./xs-security.json
      service: xsuaa
      service-plan: application

xs-security.json

{
        "xsappname": "external-service",
        "tenant-mode": "dedicated",
        "scopes": [],
        "attributes": [],
        "role-templates": []
    }

package.json

{
  "name": "external-service",
  "version": "1.0.0",
  "description": "A simple CAP project.",
  "repository": "<Add your repository here>",
  "license": "UNLICENSED",
  "private": true,
  "dependencies": {
    "@sap/cds": "^5",
    "express": "^4"
  },
  "devDependencies": {
    "sqlite3": "^5.0.2"
  },
  "scripts": {
    "start": "cds run"
  },
  "eslintConfig": {
    "extends": "eslint:recommended",
    "env": {
      "es2020": true,
      "node": true,
      "jest": true,
      "mocha": true
    },
    "globals": {
      "SELECT": true,
      "INSERT": true,
      "UPDATE": true,
      "DELETE": true,
      "CREATE": true,
      "DROP": true,
      "CDL": true,
      "CQL": true,
      "CXL": true,
      "cds": true
    },
    "rules": {
      "no-console": "off",
      "require-atomic-updates": "off"
    }
  },
  "cds": {
    "requires": {
      "NorthWind": {
        "kind": "odata-v2",
        "model": "srv/external/NorthWind",
        "credentials": {
            "destination": "NorthWind"
        }
      }
    }
  }
}

The error states that the instance of external-service-destination in mta.yaml is not found.

Update: I managed to fixed the issue

For those who encountered this kind of issue, kindly see updated mta.yaml config. I follow this guide and it solved my issue during deployment to Cloud Foundry of BTP.

mta.yaml

_schema-version: '3.1'
ID: external-service
version: 1.0.0
description: A simple CAP project.
parameters:
  enable-parallel-deployments: true
build-parameters:
  before-all:
    - builder: custom
      commands:
        - npm ci
        - npx -p @sap/cds-dk cds build --production
modules:
  - name: external-service-srv
    type: nodejs
    path: gen/srv
    parameters:
      buildpack: nodejs_buildpack
    build-parameters:
      builder: npm-ci
    provides:
      - name: srv-api
        properties:
          srv-url: '${default-url}'
    requires:
      - name: external-service-dest
      - name: external-service-uaa
resources:
  - name: external-service-dest
    type: org.cloudfoundry.managed-service
    parameters:
      service: destination
      service-name: external-service-dest
      service-plan: lite
  - name: external-service-uaa
    type: org.cloudfoundry.managed-service
    parameters:
      path: ./xs-security.json
      service: xsuaa
      service-plan: application
      service-name: external-service-uaa
0

There are 0 answers