[英]How to use Blocks correctly to load AWS S3 credentials in Prefect?
I am using Prefect.我正在使用 Prefect。 And I tried to download a file from S3.
我试图从 S3 下载一个文件。
When I hard coded the AWS credentials, the file can be downloaded successfully:当我硬编码 AWS 凭证时,可以成功下载文件:
import asyncio
from prefect_aws.s3 import s3_download
from prefect_aws.credentials import AwsCredentials
from prefect import flow, get_run_logger
@flow
async def fetch_taxi_data():
logger = get_run_logger()
credentials = AwsCredentials(
aws_access_key_id="xxx",
aws_secret_access_key="xxx",
)
data = await s3_download(
bucket="hongbomiao-bucket",
key="hm-airflow/taxi.csv",
aws_credentials=credentials,
)
logger.info(data)
if __name__ == "__main__":
asyncio.run(fetch_taxi_data())
Now I tried to load the credentials from Prefect Blocks .现在我尝试从Prefect Blocks加载凭据。
I created a AWS Credentials Block:我创建了一个 AWS 凭证块:
However,然而,
aws_credentials_block = AwsCredentials.load("aws-credentials-block")
data = await s3_download(
bucket="hongbomiao-bucket",
key="hm-airflow/taxi.csv",
aws_credentials=aws_credentials_block,
)
throws the error:抛出错误:
AttributeError: 'coroutine' object has no attribute 'get_boto3_session'
AttributeError:“协程”object 没有属性“get_boto3_session”
And和
aws_credentials_block = AwsCredentials.load("aws-credentials-block")
credentials = AwsCredentials(
aws_access_key_id=aws_credentials_block.aws_access_key_id,
aws_secret_access_key=aws_credentials_block.aws_secret_access_key,
)
data = await s3_download(
bucket="hongbomiao-bucket",
key="hm-airflow/taxi.csv",
aws_credentials=credentials,
)
throws the error:抛出错误:
AttributeError: 'coroutine' object has no attribute 'aws_access_key_id'
AttributeError:“协程”object 没有属性“aws_access_key_id”
I didn't find any useful document about how to use it.我没有找到任何关于如何使用它的有用文档。
Am I supposed to use Blocks to load credentials?我应该使用 Blocks 来加载凭据吗? If it is, what is the correct way to use Blocks correctly in Prefect?
如果是,在 Prefect 中正确使用 Blocks 的正确方法是什么? Thanks!
谢谢!
I just found the official demo in the screenshot of the question is misleading.我刚刚发现问题截图中的官方演示具有误导性。 It misses an
await
.它错过了
await
。
After adding await
, it works now!添加
await
后,它现在可以工作了!
aws_credentials_block = await AwsCredentials.load("aws-credentials-block")
data = await s3_download(
bucket="hongbomiao-bucket",
key="hm-airflow/taxi.csv",
aws_credentials=aws_credentials_block,
)
I will open a ticket to report the issue.我会开一张票报告这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.