https://prefect.io logo
Title
a

Alireza

01/02/2023, 12:47 PM
Hi everyone! I’ve just started to learn and use Prefect. I was looking for best practices to share blocks between different workspace in Prefect cloud.
j

Jeff Hale

01/02/2023, 2:09 PM
Hi Alireza! Welcome! 🎉 Blocks are specific to a workspace, so the easiest way to duplicate them across workspaces is to instantiate them in code and then run that code when connected to one workspace, and then run that code when connected to another workspace. If the block is found in a collection or is of a custom type, you will need to register it in each workspace prior to instantiation.
🙏 1
👍 1
a

Alireza

01/03/2023, 2:34 PM
Thanks Jeff, Everything work well with normal blocks but in case of collections, still I have this problem:
Thanks Jeff, Everything work well with normal blocks but in case of collections, still I have this problem: 1. registering collections by
prefect block register -m prefect_aws.credentials
2. registering or saving the block using
Thanks Jeff, Everything work well with normal blocks but in case of collections, still I have problem: 1. registering collections by
prefect block register -m prefect_aws.credentials
2. registering or saving the block using
from prefect_aws.credentials import AwsCredentials
credentials = AwsCredentials(
        aws_access_key_id="acccess_key_id",
        aws_secret_access_key="secret_access_key"
    )
credentials.save(name='first_aws_creds', overwrite=True)
would result in this error:
raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '422 Unprocessable Entity' for url 
'<https://api.prefect.cloud/api/accounts/../>
j

Jeff Hale

01/03/2023, 3:15 PM
Hi Alireza. You might want to create the block via the UI as shown below. The docstring and type hints don’t show all the relevant fields for creating the block, but that’s something we can look to add. cc @Andrew Huang
a

Andrew Huang

01/03/2023, 5:31 PM
credentials.save(name='first_aws_creds', overwrite=True)
runs into an error because block names cannot have underscores; only hyphens; I encountered that before as well and we’re working on a better exception msg
🙏 1
a

Alireza

01/03/2023, 5:34 PM
Aha! That is why sometimes it works 😄
🙌 1
a

Andrew Huang

01/03/2023, 5:50 PM
created an issue here for tracking: https://github.com/PrefectHQ/prefect/issues/8036
👍 1
:thank-you: 1
It should be fixed in the next release! Thanks for sharing your example https://github.com/PrefectHQ/prefect/pull/8038
🙌 2
:thank-you: 1
a

Alireza

01/04/2023, 8:43 AM
@Flavio Oliveira