Aws lambda 如何在Cloudformation的输出中显示lambda函数返回值
我正在寻找在Cloudformation的输出中列出AWS::Lambda::函数结果的选项 以下是AWS:Lambda::Function的cloudformation模板片段Aws lambda 如何在Cloudformation的输出中显示lambda函数返回值,aws-lambda,amazon-cloudformation,Aws Lambda,Amazon Cloudformation,我正在寻找在Cloudformation的输出中列出AWS::Lambda::函数结果的选项 以下是AWS:Lambda::Function的cloudformation模板片段 Resources: AthenaLambdaFunction: Type: 'AWS::Lambda::Function' DeletionPolicy: Delete DependsOn: - IamRoleLambdaForAthena Properties:
Resources:
AthenaLambdaFunction:
Type: 'AWS::Lambda::Function'
DeletionPolicy: Delete
DependsOn:
- IamRoleLambdaForAthena
Properties:
Code:
ZipFile: |
import boto3
import botocore
import os
ath = boto3.client('athena')
def handler(event, context):
outputBucket = os.environ.get("outputBucket")
QSTRING = 'select * from tableName limit 10'
response = ath.start_query_execution(QueryString=str(QSTRING), ResultConfiguration={'OutputLocation': outputBucket})
s3BucketOut = output_bucket + response['ResponseMetadata']['RequestId']
return s3BucketOut
Handler: index.handler
Runtime: python3.6
MemorySize: 128
Role: !GetAtt IamRoleLambdaForAthena.Arn
Timeout: 30
Environment:
Variables:
outputBucket: !Ref OutputS3Bucket
我想在Cloudformation的输出中显示lambda函数s3BucketOut返回的值。下面的代码不起作用
Outputs:
LambdaFunctionOutput:
Value: !Ref AthenaLambdaFunction.s3BucketOut
Description: Return Value of Lambda Function
有什么建议吗。TIA您可以创建一个被称为Lambda支持的自定义资源,您可以在堆栈创建期间使用它来获取创建类型的信息位 更多信息可在此处找到
你已经完成一半了。使用代码,您创建了要运行的AWS Lambda函数。现在,您需要让这个函数在CloudFormation上运行并捕获它的值。请注意,您需要对代码进行一些小的更改,以允许CloudFormation捕获值 完整代码与此类似: 资源: AthenalAmbda功能: 类型:“AWS::Lambda::Function” 删除策略:删除 德彭森: -天竺葵 特性: 代码: ZipFile:| 进口boto3 导入botocore 导入操作系统 导入CFN响应需要导入此项以回复CloudFormation ath=bot3.客户“雅典娜” def handlerevent,上下文: outputBucket=os.environ.getoutputBucket QSTRING='select*from tableName limit 10' response=ath.start\u query\u executionQueryString=strQSTRING,ResultConfiguration={'OutputLocation':outputBucket} s3BucketOut=输出_bucket+响应['ResponseMetadata']['RequestId'] responseData={}已添加 响应数据['S3BucketOut']=S3BucketOut已添加 cfnresponse.sendevent,上下文,cfnresponse.SUCCESS,responseData返回已修改 处理程序:index.Handler 运行时:python3.6 记忆化:128 角色:!格塔特·亚莫拉姆·达佛拉提娜·阿恩 超时时间:30 环境: 变量: 输出桶:!参考输出3桶 职业: 类型:自定义::S3BucketOut 特性: ServiceToken:!GetAtt AthenaLambdaFunction.Arn 地区:!Ref AWS::区域 产出: LambdaFunction输出: 值:!GetAtt S3BuckeTouting.S3BucketOut Description:Lambda函数的返回值 参考资料: