如何创建一个由对流层的 cloudwatch 事件定期调用的 Lambda?

How do I create a Lambda that's called on a regular interval by a cloudwatch event with troposphere?

我创建了一个 Lambda 函数,我想每 5 分钟或每天一次或其他任何方式调用一次。我如何设置对流层?

我到处都找不到例子。

对于下一个人,这是我最终想出的工作代码(在这种情况下,我试图 运行 "report"):

from troposphere import (
    Join, Ref, GetAtt, awslambda, iam, events, Template
)

template = Template()

report_lambda = template.add_resource(awslambda.Function(
    "MyLambda",
    Code=awslambda.Code(
        S3Bucket="my-bucket"
        S3Key="lambdas/my-lambda.jar"
    ),
    Description="Lambda task that runs every 5 minutes.",
    FunctionName="MyFunction",
    Handler="com.mycompany.MyLambda::handleRequest",
    Runtime="java8",
    Timeout=120,
    Role=GetAtt("MyLambdaRole", "Arn"),
    MemorySize=512
))

report_rule = template.add_resource(events.Rule(
    "MyRule",
    ScheduleExpression="rate(5 minutes)",
    Description="My Lambda CloudWatch Event",
    State="ENABLED",
    Targets=[
        events.Target(
            "MyLambdaTarget",
            Arn=GetAtt(report_lambda.title, "Arn"),
            Id="MyLambdaId"
        )
    ]
))

template.add_resource(awslambda.Permission(
    'MyInvokePermission',
    FunctionName=GetAtt(report_lambda.title, 'Arn'),
    Action='lambda:InvokeFunction',
    Principal='events.amazonaws.com',
    SourceArn=GetAtt(report_rule.title, 'Arn'),
))

print(template.to_json())