0

I'm trying to create an IBM Cloud Function web action from some python code. This code has a dependency which isn't in the runtime, so I've followed the steps here to package the dependency with my code. I now need to create the action on the cloud for this package, using the steps described here. I've got several issues.

The first is that I want to check that this will be going into the right namespace. However though I have several, none are showing up when i do ibmcloud fn namespace list, I just get the empty table with headers. I checked that I was targeting the right region using ibmcloud target -r eu-gb.

The second is that when I try to bypass the problem above by creating a namespace from the command line using ibmcloud fn namespace create nyNamespaceName, it works, but I then check on the web UI, and this new namespace has been created in the Dallas region instead of the London one… I can’t seem to get it to create a namespace in the region that I am currently targeting for some reason, it’s always Dallas.

The third problem is that when I try to follow the steps 2 and 3 from here regardless, accepting that it will end up in the unwanted Dallas namespace, by running the equivalent of ibmcloud fn action create demo/hello <filepath>/hello.js --web true, it keeps telling me I need to target an org and a space. But my namespace is an IAM namespace, it doesn’t have an org and a space, so there are none to give?

Please let me know if I’m missing something obvious or have misunderstood something, because to me it feels like the CLI is not respecting the targeting of a region and not handling IAM stuff correctly.

Edit: adding code as suggested, but this code runs fine locally, it's the CLI part that I'm struggling with?

import sys
import requests
import pandas as pd
import json
from ibm_ai_openscale import APIClient

def main(dict):

    # Get AI Openscale GUID 
    AIOS_GUID = None
    token_data = {
        'grant_type': 'urn:ibm:params:oauth:grant-type:apikey',
        'response_type': 'cloud_iam',
        'apikey': 'SOMEAPIKEYHERE'
    }

    response = requests.post('https://iam.bluemix.net/identity/token', data=token_data)
    iam_token = response.json()['access_token']
    iam_headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer %s' % iam_token
    }

    resources = json.loads(requests.get('https://resource-controller.cloud.ibm.com/v2/resource_instances', headers=iam_headers).text)['resources']
    for resource in resources:
        if "aiopenscale" in resource['id'].lower():
            AIOS_GUID = resource['guid']

    AIOS_CREDENTIALS = {
        "instance_guid": AIOS_GUID,
        "apikey": 'SOMEAPIKEYHERE',
        "url": "https://api.aiopenscale.cloud.ibm.com"
    }

    if AIOS_GUID is None:
        print('AI OpenScale GUID NOT FOUND')
    else:
        print('AI OpenScale FOUND')

    #GET OPENSCALE SUBSCRIPTION

    ai_client = APIClient(aios_credentials=AIOS_CREDENTIALS)
    subscriptions_uids = ai_client.data_mart.subscriptions.get_uids()
    for sub in subscriptions_uids:
        if ai_client.data_mart.subscriptions.get_details(sub)['entity']['asset']['name'] == "MYMODELNAME":
                subscription = ai_client.data_mart.subscriptions.get(sub)

    #EXPLAINABILITY TEST
    sample_transaction_id="SAMPLEID"
    run_details = subscription.explainability.run(transaction_id=sample_transaction_id, cem=False)

    #Formating results
    run_details_json = json.dumps(run_details)

    return run_details_json
71ML
  • 3
  • 2
  • post some code. – Claire Jun 27 '19 at 17:09
  • A lot of text and no code. Show the steps done and errors or other output – data_henrik Jun 28 '19 at 07:19
  • Have added code - hope it helps? can try to reduce wall of text, sorry – 71ML Jun 28 '19 at 09:58
  • i've also tried targetting my cf namespace but then i get the exact same error as [this one](https://stackoverflow.com/questions/54362064/ibmcloud-create-action-through-cli), for the same reasons I think (lite account?) – 71ML Jun 28 '19 at 10:10

1 Answers1

0

I know the OP said they were 'targeting the right region'. But I want to make it clear that the 'right region' is the exact region in which the namespaces you want to list or target are located.

Unless you target this region, you won't be able to list or target any of those namespaces.

This is counterintuitive because

  • You are able to list Service IDs of namespaces in regions other than the one you are targeting.
  • The web portal allows you to see namespaces in all regions, so why shouldn't the CLI?

I was having an issue very similar to the OP's first problem, but once I targeted the correct region it worked fine.

Ben Hogan
  • 55
  • 5