Python – AWS S3 keep N latest artifacts

This script gets a list of all directories in the bucket and deletes all objects in each directory, except for the last "N" specified. To run the script, you need to pass two arguments: Bucket name Number of last stored objects How to use it:   main.py:

AWS – Lambda: kubectl

An example of how you can create entities in Kubernetes using AWS Lambda. The function will be in Python3, so we will use Kubernetes Python Client More usage examples can be found here. Since AWS Lambda does not support this package, we will pack the "kubernetes" and "boto3" modules in our function. "boto3" is needed … Continue reading "AWS – Lambda: kubectl"

FIX ERROR – AWS Lambda Python: "main() takes 0 positional arguments but 2 were given"

When trying to execute the Lambda Python function, the following error occurs: { "errorMessage": "main() takes 0 positional arguments but 2 were given", "errorType": "TypeError", "stackTrace": [ " File \"/var/runtime/bootstrap.py\", line 131, in handle_event_request\n response = request_handler(event, lambda_context)\n" ] }   Solution: From the message, we see that we use the "main" function as a … Continue reading "FIX ERROR – AWS Lambda Python: "main() takes 0 positional arguments but 2 were given""

AWS – Script to get metrics from CloudWatch

Python3 sample script to get metrics from AWS CloudWatch. In the example, we get the maximum value in the last minute and display only the value, this is necessary if you want to collect metrics for example in Zabbix.   Script: