如何在CloudFormation模板中描述AWS Lambda函数测试事件? [英] How to describe AWS Lambda function test events in CloudFormation template?
问题描述
我在CloudFormation模板中描述了现有的AWS Lambda函数,并且面临下一个问题。在Lambda中,我们配置了一些测试事件,这些事件可以帮助我们验证一些用例(我的意思是下面的屏幕截图中的功能)。
从cloudformation模板调用功能。资源属性允许AWS CloudFormation创建自定义有效负载以发送到Lambda函数。
示例代码:
资源:
EnableLogs:
类型:自定义:: EnableLogs
版本:'1.0'
属性:
ServiceToken:arn:aws:lambda:us-east-1:acc:function:rds-EnableRDSLogs-1O6XLL6LWNR5Z
DBInstanceIdentifier:mydb
事件参数提供资源属性。例如:
event ['ResourceProperties'] ['DBInstanceIdentifier']
I describe existing AWS Lambda function in CloudFormation template and I face with the next issue. In our Lambda we configured few test events which helps us to verify some usecases (I mean functionality from the screenshot below).
But I don't see any abilities to add these test events to the CloudFormation template. AWS documentation don't help me with that. Is that possible at all or are there any workarounds how to export and import Lambda function test events?
Lambda test functionality is available only in the UI console, You can use Cloudformation Custom Resource to invoke a function from a cloudformation template. Resource properties allow AWS CloudFormation to create a custom payload to send to the Lambda function.
Sample code:
Resources:
EnableLogs:
Type: Custom::EnableLogs
Version: '1.0'
Properties:
ServiceToken: arn:aws:lambda:us-east-1:acc:function:rds-EnableRDSLogs-1O6XLL6LWNR5Z
DBInstanceIdentifier: mydb
the event parameter provides the resource properties. ex:
event['ResourceProperties']['DBInstanceIdentifier']
这篇关于如何在CloudFormation模板中描述AWS Lambda函数测试事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!