Maksym Domariev
01/03/2025, 6:51 AMMarvin
01/03/2025, 6:51 AMSecret
block to store and retrieve sensitive information securely. This is particularly useful when integrating with third-party services.
- Example:
python
from prefect import flow
from prefect.blocks.system import Secret
# Store a secret
secret = Secret(value="my-secret-value")
secret.save("my-secret", overwrite=True, _sync=True)
# Use the secret in a flow
@flow
def my_flow():
import os
print(os.environ["MY_SECRET"])
2. Environment Variables:
- You can also use environment variables in your prefect.yaml
file by templating them with {{ $ENV_VAR_NAME }}
syntax. This requires that the environment variable is set on the machine where prefect deploy
is run.
3. Prefect Documentation:
- For more detailed steps and examples, refer to the Prefect 3.0 Secrets Documentation.
These approaches ensure your secrets are managed securely while being accessible within your Prefect jobs. If you're using Prefect Cloud, the values are stored in an encrypted format for additional security.