FROM public.ecr.aws/lambda/python:3.11
RUN yum install -y tar gzip
RUN pip3 install --upgrade pip
COPY ./lambda ${LAMBDA_TASK_ROOT}
RUN pip3 install -r ${LAMBDA_TASK_ROOT}/requirements.txt
CMD ["appname.lambda_handler"]
Docker
Python Script "build_docker_image.py" for building Docker image tiggered by terraform
MySQL does not start with error message:
MySQL Shutdown Unexpectedly /
MySQL wurde unerwartet beendet
1. Rename folder mysql/data to mysql/data_old
2. Make a copy of mysql/backup folder and name it as mysql/data
3. Copy all your database folders from mysql/data_old into mysql/data (except mysql, performance_schema, and phpmyadmin folders)
4. Copy mysql/data_old/ibdata1 file into mysql/data folder
5. Start MySQL from XAMPP control panel
Python
convert image from svg to png
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPM
drawing = svg2rlg("image.svg")
renderPM.drawToFile(drawing, "image.png", fmt="PNG")
Python
CSV to PARQUET
import pandas as pd
df = pd.read_csv('example.csv')
df.to_parquet('output.parquet')
Python
Get Password / Key Pair from p8 and AWS Secret Manager.
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.asymmetric import dsa
from cryptography.hazmat.primitives import serialization
import json
# This function returns the private key of a key pair from a .p8 file
def get_private_key_from_file(path, password):
"""Load the private key from the given path securely."""
with open(path, "rb") as key_file:
private_key = serialization.load_pem_private_key(
key_file.read(),
password=password.encode() if password else None,
backend=default_backend()
)
return private_key.private_bytes(
encoding=serialization.Encoding.DER,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption())
# This function returns the private key of a key pair from AWS Secret Manager
# To setup the AWS Secret Manager put the private key in the "Plaintext" section of the Secret value (not: key / value)
def get_private_key_from_secretmanager(session, region, secret_name):
client = session.client(
service_name='secretsmanager',
region_name=region
)
# Retrieve the secrects details from AWS
response = client.get_secret_value(SecretId=secret_name)
# Extract the secrect key
key = response['SecretString']
private_key= serialization.load_pem_private_key(
key.encode('utf-8'),
password=None,
backend=default_backend()
)
return private_key.private_bytes(
encoding=serialization.Encoding.DER,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption())
# This function returns the key pair from AWS Secret Manager
# To setup the AWS Secret Manager put key and value into the "Key/value" section of Secret value (no key / value)
def get_key_value_from_secretmanager(session, region, secret_name):
client = session.client(
service_name='secretsmanager',
region_name=region
)
# Retrieve the secrects details from AWS
response = client.get_secret_value(SecretId=secret_name)
# Extract the key / value
secretjson = json.loads(response['SecretString'])
key, value = next(iter(secretjson.items()))
return key, value