Ansible Cloudwatch rule reports failed invocations

前端 未结 3 1922
旧巷少年郎
旧巷少年郎 2021-02-13 07:28

I have created an AWS lambda that works well when I test it and when I create a cron job manually through a cloudwatch rule.

It reports metrics as invocations (not faile

3条回答
  •  野的像风
    2021-02-13 07:47

    I've lost hours with this too, same error and same confusion (Why there isn't a log for failed invokations?), I'm going to share my ""solution"", it will solve the problem to someone, and will help others to debug and find the ultimate solution.

    Note: Be carefull, this could allow any AWS account execute your lambda functions

    Since you got invoke the function by creating the rule target manually, I assume you added the invoke permission to the lambda from CloudWatch, however it looks like the Source Account ID is different when the event is created by cli/api and when is created by de AWS dashboard/console

    If you are adding the Source Account condition in the lambda invoke permission from principal "events.amazonaws.com" to prevent any AWS account execute your lambdas just remove it (under your responsability!).

    So, if your lambda policy looks like this:

    {
        "Sid": "",
        "Effect": "Allow",
        "Principal": {
            "Service": "events.amazonaws.com"
        },
        "Action": "lambda:InvokeFunction",,
        "Condition": {
            "StringEquals": {
                "AWS:SourceAccount": ""
            }
        },
        "Resource": "arn:aws:lambda:::function:"
    }
    

    Remove the "Condition" field

    {
        "Sid": "sid",
        "Effect": "Allow",
        "Principal": {
            "Service": "events.amazonaws.com"
        },
        "Action": "lambda:InvokeFunction",,
        "Resource": "arn:aws:lambda:::function:"
    }
    

    And "maybe" it will work for you.

    I think something weird it is happening with the cloudwatch event owner/creator data when the event is created by cli/api... maybe a bug? Not sure. I will keep working on it

提交回复
热议问题