CDKでLambdaのトリガーにcloudwatch eventsをトリガーに指定したいのですが
書き方がわかりません。
お教えいただけたら幸いです。
cdk ver: 1.13.1
言語: Python
from aws_cdk import (
core,
aws_iam,
aws_ec2,
aws_stepfunctions,
aws_lambda,
aws_cloudwatch,
aws_events,
aws_events_targets,
)
class CdkPrjStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
lambda_function = aws_lambda.Function(
self,
id='lambda',
code=aws_lambda.Code.asset('trigger_lambda/lambda'),
handler='lambda_function.lambda_handler',
runtime=aws_lambda.Runtime.PYTHON_3_7,
function_name='sfn-trigger',
environment=None,
timeout=core.Duration.seconds(900),
reserved_concurrent_executions=1,
vpc=None,
vpc_subnets=None,
role=None,
)
schedule = aws_events.Schedule.cron(
year='*',
month='*',
day='*',
hour='15',
minute='*',
)
rule = aws_events.Rule(
self,
id='cloudwatch-event',
description=None,
enabled=True,
event_pattern=None,
schedule=schedule,
rule_name='ami-region-copy',
)
rule_target_input = aws_events.RuleTargetInput.bind(
self,
rule=rule,
)
aws_events_targets.LambdaFunction(
handler=lambda_function,
event=rule_target_input,
)