<@ULVA73B9P> how would you authenticate to the clo...
# ask-marvin
v
@Marvin how would you authenticate to the cloud when building a worker agent using the official image prefecthq/prefect:2-python3.11? can you pass env vars into the container itself or some other way?
m
To authenticate a worker in Prefect Cloud using the official image
prefecthq/prefect:2-python3.11
, you can pass environment variables into the container. Specifically, you'll need to set the following environment variables: - `PREFECT_API_URL`: Set this to the API URL of your Prefect Cloud instance, such as
<https://api.prefect.cloud/api/accounts/<ACCOUNT-ID>/workspaces/<WORKSPACE-ID>>
. Replace
<ACCOUNT-ID>
and
<WORKSPACE-ID>
with your actual account and workspace IDs, which you can locate in the UI's dashboard URL. - `PREFECT_API_KEY`: Use an active API key here. Here's an example of how to set these environment variables before running a command to deploy your worker:
Copy code
bash
export PREFECT_API_URL='<https://api.prefect.cloud/api/accounts/<ACCOUNT-ID>/workspaces/<WORKSPACE-ID>>'
export PREFECT_API_KEY='<YOUR-API-KEY>'
Afterwards, you can launch your worker with a command like the following, replacing necessary placeholders:
Copy code
bash
gcloud run deploy prefect-worker --image=prefecthq/prefect:2-latest \
  --set-env-vars PREFECT_API_URL=$PREFECT_API_URL,PREFECT_API_KEY=$PREFECT_API_KEY \
  --service-account <YOUR-SERVICE-ACCOUNT-NAME> \
  --no-cpu-throttling \
  --min-instances 1 \
  --args "prefect","worker","start","--install-policy","always","--with-healthcheck","-p","<WORK-POOL-NAME>","-t","cloud-run"
For your reference: - GCP Worker Guide - Settings Guide Keep in mind, the Prefect Cloud API URL and API Key are sensitive pieces of information that should be kept secure and preferably managed through an appropriate secrets management service.