将参数传递给 AWS Cloudwatch 事件目标 lambda 函数
Pass parameters to AWS Cloudwatch event target lambda function
我想将参数传递给由 AWS Cloudwatch 事件调用的 lambda 函数。参数名称为alarmActions
,事件规则我的CFT模板如下:
"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"]] }, "\" }"]] }
}]
}
}
我已经使用 Input
参数传递 JSON 文本。没有太多关于它的文档。我只是想找到正确的方法。
我找到了解决方案。我以错误的方式引用了 lambda 中的参数。
我的 lambda 函数是这样的:
def func(event, context, alarmActions)
{
print(alarmActions)
}
当我进行以下更新时它起作用了:
def func(event, context)
{
print(event['alarmActions'])
}
我想将参数传递给由 AWS Cloudwatch 事件调用的 lambda 函数。参数名称为alarmActions
,事件规则我的CFT模板如下:
"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"]] }, "\" }"]] }
}]
}
}
我已经使用 Input
参数传递 JSON 文本。没有太多关于它的文档。我只是想找到正确的方法。
我找到了解决方案。我以错误的方式引用了 lambda 中的参数。
我的 lambda 函数是这样的:
def func(event, context, alarmActions)
{
print(alarmActions)
}
当我进行以下更新时它起作用了:
def func(event, context)
{
print(event['alarmActions'])
}