【发布时间】:2018-05-21 13:16:51
【问题描述】:
AWS 加载的问题,但有谁知道在 Lambda 中访问 Athena 查询字符串(在 CloudFormation 中)的正确方法是什么?
我已经在 CloudFormation 中设置了 Athena NamedQuery 和 Lambda。抽象出一些更具体的项目细节,我的一般形式是:
MyQuery:
Type: AWS::Athena::NamedQuery
Properties:
Database: "mydatabase"
Name: "DataQuery"
QueryString: SELECT * FROM mydatabase
MyLambda:
Type: AWS::Serverless::Function
Properties:
Handler: 'handlers.migration_handler'
Runtime: python3.6
CodeUri:
Bucket: BATS::SAM::CodeS3Bucket
Key: BATS::SAM::CodeS3Key
Description: Migrates data from output of Athena query to S3
Policies:
- AmazonS3FullAccess
- AWSLambdaExecute
- AmazonAthenaFullAccess
Environment:
Variables:
MY_QUERY:
Ref: MyQuery
当我为 lambda 编写处理程序时,我想调用:
athena_client = boto3.client('athena')
response = athena_client.start_query_execution(
QueryString = os.environ['MY_QUERY']
ResultConfiguration = {'OutputLocation: 's3://my-bucket'}
)
但是,QueryString 必须是一个字符串,所以目前这不起作用。我想访问 MY_QUERY 中的 QueryString 属性,我觉得我很接近,但我不太确定如何完成最后一步。在这里的任何帮助将不胜感激。
【问题讨论】:
标签: aws-lambda amazon-cloudformation amazon-athena