In Prefect 2.0, I’m trying to create a Deployment ...
# prefect-community
r
In Prefect 2.0, I’m trying to create a Deployment which takes arguments from a configuration stored in Prefect Cloud as a custom block. Here is the sample code:
Copy code
config = CustomConfig.load('my_block')

Deployment(
    name="My deployment",
    flow=my_flow,
    parameters={
        "password": config.password
    }
)
when I run this command from CLI
Copy code
prefect deployment create my_deployment.py
I get this error
Copy code
AttributeError: 'coroutine' object has no attribute 'password'

Failed to load deployments from 'my_deployment.py'
sys:1: RuntimeWarning: coroutine 'Block.load' was never awaited
How can I do that?
a
Try out the Secret block instead that just got released
r
thanks @Anna Geller, but I think my situation is different from the example you provided. I know I can save and load blocks within flows, but at the moment I want to create a deployment as described in https://orion-docs.prefect.io/concepts/deployments/#creating-deployments by using the CLI. I’ve supposed that load would also work outside a flow but it looks like it doesn’t. Now I’m trying to create the deployment directly in Python with
Deployment.create()
, but now I’m facing with this error:
here is the code
Copy code
if __name__ == '__main__':

    config = CustomConfig.load('my_setup')

    deployment = Deployment(
        name="MyDeployment",
        flow=my_flow,
        parameters={
            "password": config.password,
            "slack_webhook": config.slack_webhook        }
    )
    deployment.create()
and I get this
Copy code
TypeError: Object of type 'AsyncWebhookClient' is not JSON serializable
so it looks like Pydantic is failing in serializing the Slack Webhook Block
so at the end I’ve fixed by doing this
Copy code
if __name__ == '__main__':

    config = CustomConfig.load('my_setup')

    deployment = Deployment(
        name="MyDeployment",
        flow=my_flow,
        parameters={
            "password": config.password,
            "slack_webhook": config.slack_webhook.url        }
    )
    deployment.create()
nevertheless, it could be handy to be able to quickly inject a block stored in the cloud into a deployment
a
we'll have more Deployment recipes after GA release, it should get easier in the next weeks
109 Views