def __init__(self, app: App, id: str, txt: str, env: dict, policies: PolicyStatement, domain: str, hosted_zone_id: str) -> None: super().__init__(app, id) env['HOSTED_ZONE_ID'] = hosted_zone_id self.function = SingletonFunction(self, '{}Function'.format('{}'.format(id)), uuid=str(uuid4()), code=Code.inline(txt), runtime=Runtime( 'python3.7', supports_inline_code=True), handler='index.handler', environment=env) policy = Policy(self, '{}Policy'.format(id)) self.function.role.attach_inline_policy(policy) policy.add_statements(policies) rule_target = LambdaFunction(self.function) current_time = datetime.now() run_time = current_time + timedelta(minutes=3) run_schedule = Schedule.cron(year=str(run_time.year), month=str(run_time.month), day=str(run_time.day), hour=str(run_time.hour), minute=str(run_time.minute)) self.rule = Rule(self, '{}Rule'.format(id), enabled=True, schedule=run_schedule, targets=[rule_target])
def __init__( self, app: App, id: str, code_txt: str, runtime: str, handler: str, env: dict, policy: str) -> None: super().__init__(app, id) function_role = Role( self, 'NonLazyRole', assumed_by=ServicePrincipal('lambda.amazonaws.com')) self.function = Function( self, 'Function'.format('{}'.format(id)), code=Code.inline(code_txt), runtime=Runtime('python3.7', supports_inline_code=True), handler='index.create', environment=env, initial_policy=[policy], tracing=Tracing.ACTIVE, role=function_role )