简体   繁体   English

如何正确使用 Blocks 在 Prefect 中加载 AWS S3 凭证?

[英]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.

相关问题 如何从 S3 加载泡菜文件以在 AWS Lambda 中使用? - How to load a pickle file from S3 to use in AWS Lambda? Aws将凭证传递给ansible s3模块 - Aws passing credentials to ansible s3 module 无凭据错误:尝试将文件从 aws s3 存储桶加载到 jupyter 笔记本中 - No Credentials Error: Trying to load files from aws s3 bucket into jupyter notebook Python:如何从 AWS S3 读取和加载 excel 文件? - Python: How to read and load an excel file from AWS S3? Python 3:如何将 AWS S3 中的多个 CSV 加载到 Pandas dataframe 中? - Python 3: How to load multiple CSVs in AWS S3 into a Pandas dataframe? 在本地运行 Pyspark 以访问 S3 中的镶木地板文件错误:“无法从链中的任何提供商加载 AWS 凭证” - Running Pyspark locally to access parquet file in S3 Error: “Unable to load AWS credentials from any provider in the chain” 我应该如何将我的s3凭据传递给AWS上的Python lambda函数? - How should I pass my s3 credentials to Python lambda function on AWS? 无凭据错误 - 使用 boto3 和 aws s3 存储桶 - No Credentials Error - Using boto3 and aws s3 bucket Boto3 S3实例的AWS凭证放在何处 - Where to put AWS credentials for Boto3 S3 instance 使用 AWS S3 时 Python 中的凭据问题 - credentials issue in Python while using AWS S3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM