I’d like to use a Secret stored in Prefect Cloud i...
# prefect-community
s
I’d like to use a Secret stored in Prefect Cloud in my run config. I have stored the secret using
Copy code
>>> from prefect import Client
>>> client = Client()
>>> client.set_secret(name="test", value="test")
>>> client.set_secret(name="AWS_ACCOUNT_ID-dev", value="123456789098")
It seems like I should be able to use
Copy code
from prefect.client import Secret

aws_account_id = Secret('AWS_ACCOUNT_ID-' + RUN_ENV).get()
However, I receive the following error:
Copy code
ValueError: Local Secret "AWS_ACCOUNT_ID-dev" was not found.
How can I retrieve a secret value outside of a task?
k
If executing locally, there is a config/env variable and the default is to pull local secrets. Set
Copy code
export PREFECT__CLOUD__USE_LOCAL_SECRETS=false
and this will pull the Cloud Secret
This is set to false for agent/cloud runs
s
Thanks. Where should I have found tis parameter/config setting?
k
I guess it’s not documented on the Secrets page but more generally configurable stuff can be found in the config.toml
s
Ah. Should I have this config file stored locally? Do the config selections get uploaded with a flow?
k
You need them stored on where the flow is running, or you can pass the env variables
Copy code
PREFECT__CLOUD__XXX_XXX
for example to your flow to them to take effect
s
Thanks so much!
@Kevin Kho Following up on this… • If I set via
export PREFECT…SECRETS=false
I get the expected behavior. • If I change the default config path with
export PREFECT__USER_CONFIG_PATH=/Users/slloyd/projects/my_path/.prefect
with
use_local_secret=false
I do not get the expected behavior • If I put the file in
$HOME/.prefect/config.toml
with
use_local_secret=false
in a docker image I do not get the expected behavior. Do you know what I am missing?
k
I have noticed the same thing too with the
config.toml
in Docker. Would you be willing to write an issue about it? I can also open one and you can add your details there? You can use the RunConfig as that works