Répondre

3

Pour la prochaine personne, voici le code de travail que je suis finalement arrivé avec:

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 minute.", 
    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())