

CDKでLambdaのトリガーにcloudwatch eventsをトリガーに指定したいのですが  
書き方がわかりません。

お教えいただけたら幸いです。

cdk ver: 1.13.1  
言語: Python

[code]

    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,
            )
    
[/code]


CC BY-SA 4.0
2019-10-17T04:11:48.190
59760
2019-10-17T07:44:11.087
2019-10-17T07:44:11.087
19110
36233
question
python python3 aws
CDKでLambdaのトリガーにcloudwatch eventsを指定したい


ruleにtargetsのこのように指定することで解決できました

[code]

    rule = aws_events.Rule(
                self,
                id='cloudwatch-event',
                description=None,
                enabled=True,
                event_pattern=None,
                schedule=schedule,
                rule_name='ami-region-copy',
                targets=[aws_events_targets.LambdaFunction(handler=lambda_function)],
            )
    
[/code]


CC BY-SA 4.0
2019-10-17T05:20:50.223
59763
2019-10-17T05:20:50.223
36233
59760
answer