Hi everyone! Iโ€™ve just started to learn and use Pr...
# prefect-cloud
a
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
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
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
Copy code
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:
Copy code
raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '422 Unprocessable Entity' for url 
'<https://api.prefect.cloud/api/accounts/../>
j
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
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
Aha! That is why sometimes it works ๐Ÿ˜„
๐Ÿ™Œ 1
a
created an issue here for tracking: https://github.com/PrefectHQ/prefect/issues/8036
๐Ÿ‘ 1
๐Ÿ™ 1
It should be fixed in the next release! Thanks for sharing your example https://github.com/PrefectHQ/prefect/pull/8038
๐Ÿ™Œ 2
๐Ÿ™ 1
a
@Flavio Oliveira