Scheduling reports with AWS Lambda
This requires that you use an AMD64 system and Docker.
To use the Reporting CLI with AWS Lambda, you need to do the following preliminary steps.
- Get an AWS account. For instructions, see in the AWS Account Management reference guide.
- Set up an Amazon Elastic Container Registry (ECR). For instructions, see Getting started with Amazon ECR using the AWS Management Console.
You need to assemble the container image by running a Dockerfile. When you run the Dockerfile, it downloads the OpenSearch artifact required to use the Reporting CLI. To learn more about Dockerfiles, see Dockerfile reference.
Copy the following sample configurations into a Dockerfile:
Next, run the following build command within the same directory that contains the Dockerfile:
Step 2: Create a private repository with Amazon ECR
Give your repository the name .
In addition to the Amazon ECR instructions, you need to make several adjustments for the Reporting CLI to function properly as described in the following steps in this procedure.
You need to get several commands from the AWS ECR Console to run within the Dockerfile directory.
- Choose view push commands.
- Copy and run each command shown in Push commands for opensearch-reporting-cli sequentially in the Dockerfile directory.
For more details about Docker push commands, see in the Amazon ECR user guide.
Step 4: Create a Lambda function with the container image
Now that you have a container image created for the Reporting CLI, you need to create a function defined as the container image.
- Open the AWS Lambda console and choose .
- Choose Create function, then choose Container image and fill in a name for the function.
- In Container image URI, choose Browse images and select for the image repository.
- In Images select the image, and choose Select image.
- In Architecture, choose x86_64.
- Choose Create function.
- Go to Lambda > functions and choose the function you created.
Next, test the function either by providing values JSON format or by providing AWS Lambda environment variables.
- If the function contains fixed values, such as email address you do not need a JSON file. You can specify an environment variable in AWS Lambda.
- If the function takes a variable key-value pair, then you need to specify the values in the JSON with the same naming convention as command options, for example the option requires the username and password.
The following example shows fixed values provided for the sender and recipient email addresses:
To learn more about AWS Lambda functions, see Deploying Lambda functions as container images in the AWS Lambda documentation.
Set the trigger to start running the report. AWS Lambda can use any AWS service as a trigger, such as SNS, S3, or an AWS CloudWatch EventBridge.
- In the Triggers section, choose Add trigger.
- Select a trigger from the list. For example, you can set an AWS CloudWatch Event. To learn more about Amazon ECR events you can schedule, see Sample events from Amazon ECR.
- Choose Test to initiate the function.
(Optional) Step 6: Add the role permission for Amazon SES
If you want to use Amazon SES for the email transport, you need to set up permissions.
- Select Configuration and choose Execution role.
- In Summary, choose Permissions.
- Add the permissions for the Amazon SES resource that you want to use.
To learn more about setting role permissions, see Permissions in the AWS Lambda user guide.