I’m having some trouble using resources. I’ve crea...
# ask-community
r
I’m having some trouble using resources. I’ve created one with the following code: *Text moved to thead to avoid long message
dagster bot responded by community 1
1
Copy code
@resource
def get_credentials():
    """
    This function will be used to get the credentials to make API Requests.
    """
    return {
        "X-RapidAPI-Key": os.environ["X-RAPIDAPI-KEY"],
        "X-RapidAPI-Host": os.environ["X-RAPIDAPI-HOST"],
    }
I’m defining the assets in the
___init___.py
from the resources folder like that:
Copy code
api_credentials = ResourceDefinition(
    resource_fn=get_credentials,
    config_schema={
        "X-RapidAPI-Key": String,
        "X-RapidAPI-Host": String,
    },
)

RESOURCES = {"credentials": api_credentials}
On my asset, I’m calling my resource like that:
Copy code
@asset(
    required_resource_keys={"credentials"},
)
def get_country_leagues(context: OpExecutionContext):
    headers=context.resources.credentials
But when trying to materialise the asset on the UI I have the following warning. Does anyone know how to properly use resources in this case? Thanks in advance 🙂 Adding to that, I’m not sure if the asset is not picking up because the values here are empty:
And the CLI showed that these were loaded from environment variables
image.png
But when I try to materialize on the UI, and the Asset runs fine, am I missing something?
j
delete ResourceDefinition, as resource decorator is itself ResourceDefinition
just make :
Copy code
RESOURCES = {"credentials": get_credentials}
r
Thanks, will try
j
you get the error, couse you defined config but didn't pass it. No need for config there 😉
r
Oh yeah, I don’t have the error anymore, thanks for the explanation @Jakub Zgrzebnicki!
👍 1
j
as a thank you you can bump up my post ;): https://dagster.slack.com/archives/C01U954MEER/p1682662292803589
👀 1
r
You mean to give a thumbs up? I’m fairly new to Dagster, so I might not be of much help there 😬
j
Thumbs up is ok 😉