2

我想将参数传递给由 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 文本。它周围没有太多文档。我只是想找到正确的方法。

4

1 回答 1

0

我找到了解决方案。我以错误的方式引用了 lambda 中的参数。

我的 lambda 函数是这样的:

def func(event, context, alarmActions)
{
   print(alarmActions)
}

当我进行以下更新时它起作用了:

def func(event, context)
{
   print(event['alarmActions'])
}
于 2020-09-02T08:53:26.503 回答