1. CloudWatch EventRule for LLM Batch Prediction Jobs

    Python

    To create a CloudWatch Event Rule for AWS Lambda long-running machine learning (LLM) batch prediction jobs, you would typically use the aws.cloudwatch.EventRule for defining the rule and aws.cloudwatch.EventTarget to specify the target for the event. This Event Rule can be set up to trigger on a schedule (e.g., run every hour) or in response to certain AWS service events.

    Below is a simple Pulumi program written in Python that sets up a CloudWatch Event Rule which is triggered based on a specified schedule. The event target in this example is assumed to be an AWS Lambda function that would handle the initiation or processing of LLM batch prediction jobs.

    import pulumi import pulumi_aws as aws # The ARN of the Lambda function you want to invoke for the LLM Batch Prediction Jobs # Replace 'your_lambda_function_arn' with the actual ARN of your Lambda function. lambda_function_arn = 'your_lambda_function_arn' # Create a CloudWatch Event Rule for the scheduled LLM batch prediction job # This particular rule is scheduled to run every hour using the 'cron' syntax. batch_prediction_event_rule = aws.cloudwatch.EventRule("batchPredictionJobRule", schedule_expression="cron(0 * * * ? *)", description="Trigger LLM Batch Prediction Jobs on a scheduled basis." ) # Define the target for the CloudWatch Event Rule, which is the Lambda function in this case. # Here we are associating the event rule with the Lambda function specified above. aws.cloudwatch.EventTarget("batchPredictionJobTarget", rule=batch_prediction_event_rule.name, arn=lambda_function_arn, # This `input` defines constant JSON text that will be passed to the target. # You can customize it according to the expected input by your lambda function. input="""{ "comment": "Invocation payload for LLM Batch Prediction Jobs" }""" ) # Export the Event Rule ARN so that it can be referenced outside of Pulumi if necessary. pulumi.export('event_rule_arn', batch_prediction_event_rule.arn)

    This program does the following:

    • Defines a CloudWatch Event Rule (batchPredictionEventRule) that is triggered based on a cron schedule. Here, the schedule_expression parameter schedules the jobs to run at the top of every hour.
    • Associates the Event Rule with a target, which in this case is an AWS Lambda function (batchPredictionJobTarget). The target's arn should be specified to the ARN of your Lambda function, which will be triggered by the event.
    • The Lambda function is defined elsewhere in your AWS resources and should contain the logic to initiate or handle LLM batch prediction jobs. The input JSON is an invocation payload for the lambda which can contain any necessary information your lambda function might need.
    • Finally, the CloudWatch Event Rule ARN is exported so that you can easily reference or use it from outside this Pulumi stack.

    Remember to replace 'your_lambda_function_arn' with the actual ARN of your Lambda function. The input parameter should also be customized based on your requirements and the expected input format for your Lambda function.

    Make sure you have the AWS Pulumi plugin installed and configured with the necessary permissions to create these resources in your AWS account.