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"

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:

FIX ERROR – Ansible AWS SSM: AnsibleError: An unhandled exception occurred while templating

When trying to get a value from AWS SSM, Ansible Playbook using Python3 as an interpreter generates the following error: fatal: [localhost-py3]: FAILED! => {“changed”: false, “msg”: “AnsibleError: An unhandled exception occurred while templating ‘{{ lookup(‘aws_ssm’, ‘server_listeners’, decrypt=false, region=’eu-west-1′) }}’. Error was a <class ‘ansible.errors.AnsibleError’>, original message: An unhandled exception occurred while running the lookup … Continue reading "FIX ERROR – Ansible AWS SSM: AnsibleError: An unhandled exception occurred while templating"