Hi all. I'm trying to set up a cloudwatch event ru...
# aws
f
Hi all. I'm trying to set up a cloudwatch event rule to schedule a lambda function using cron. I'm not too familiar with AWS and I think I'm missing something really obvious, and I can't seem to work this out from the Pulumi python docs. I have:
Copy code
# Create the cloudwatch event that triggers the lambda
    cloudwatchEventRule = cloudwatch.EventRule(
        resource_name="exportDashboardLambdaTrigger",
        schedule_expression=schedule_expression,  # 0 10 * * 1 10.00 AM on Monday

    )
    cloudwatchTarget = cloudwatch.EventTarget(
        "cloudwatchEventTargetLambda",
        rule=cloudwatchEventRule.id,
        arn=exportDashboardLambda.arn,
        input="{}"
    )
And the following lambda
Copy code
# Create lambda function
    lambdaDownloadExport = lambda_.Function(
        resource_name="exportDashboardLambda",
        image_uri=f".../exportdashboard:latest-{branch}",
        role=role.arn,
        package_type="Image",
        timeout=500,
        tags={
            "environment": "prod",
            "creator": "pulumi",
            "project": "exportdashboard",
        },
    )
I also defined a role to execute the lambda and gave cloudwatch permission to trigger the lambda. When I inspect the resource on AWS, I see the following (see attached img) The trigger has been created, and I can assign it manually to the function, but I'm missing how I can 'bind' the trigger to the lambda function. Any input appreciated. Thanks in advance! Jasper.
Solved 🙂
Had a typo in my lambda permission:
Copy code
# Give cloudwatch permission to trigger
lambda_.Permission(
    "exportDashboardEventTrigger",
    action="lambda:InvokeFunction",
    function=exportDashboardLambda.name,
    principal="<http://events.amazonaws.com|events.amazonaws.com>",
    source_arn=cloudWatchEventRule.arn
)
Works, and:
Copy code
# Give cloudwatch permission to trigger
lambda_.Permission(
    "exportDashboardEventTrigger",
    action="lambda:InvokeFunction",
    function=exportDashboardLambda.name,
    principal="<http://events.amazonaws.com|events.amazonaws.com>",
    source_arn=cloudWatchEventRule.arn.apply(lambda arn: f"{arn}:*")
)
Does not work