如何解决将参数传递给AWS Cloudwatch事件目标Lambda函数
我想将参数传递给由AWS Cloudwatch事件调用的lambda函数。参数名称为MM-dd-yyyy
,事件规则的CFT模板如下:
alarmActions
我使用了"LambdaInvokeScheduler": {
"Type": "AWS::Events::Rule","Properties": {
"Description": "Scheduled Rule for invoking lambda function","EventPattern": {
"source": [
"aws.ecs"
],"detail-type": [
"ECS Container Instance State Change"
],"detail": {
"clusterArn": [
{ "Fn::GetAtt": ["WindowsCluster","Arn"] }
]
}
},"State": "ENABLED","Targets": [{
"Arn": { "Fn::GetAtt": ["AlarmCreationLambdaFunction","Arn"] },"Id": "AlarmCreationLambdaFunction","Input": { "Fn::Join" : ["",[ "{ \"alarmActions\": \"",{ "Fn::Join" : [":",[ "arn:aws:sns",{ "Ref" : "AWS::Region" },{ "Ref" : "AWS::AccountId" },"CloudWatch"]] },"\" }"]] }
}]
}
}
参数来传递JSON文本。周围没有太多文档。我只是想找到正确的方法。
解决方法
我找到了解决方案。我在lambda中错误地引用了参数。
我的lambda函数是这样的:
def func(event,context,alarmActions)
{
print(alarmActions)
}
当我进行以下更新时,它起作用了:
def func(event,context)
{
print(event['alarmActions'])
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。