问题描述
我想将参数传递给由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'])
}