Observability with Elastic APM and Flask

In out last article here , we explained how to send Docker and application logs to ELK. Now is the time to add some observability to our app using Elastic APM. Configure Elastic APM First, we add Elastic APM to our Docker Compose file from last time, using the same version as Elastic Search. apm-server: image: docker.elastic.co/apm/apm-server:7.17.24 container_name: apm-server user: apm-server ports: - "8200:8200" volumes: - ./apm-server.docker.yml:/usr/share/apm-server/apm-server.yml:ro command: > --strict.perms=false -e -E output....

December 23, 2024 · 1 min · Alex Popescu

AWS Lambda and CORS preflight response

Are you struggling with a frontend application that wants to use a backend AWS Lambda API ? Do you have the next CORS problem: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response The solution is simple: implement HTTP OPTIONS method respond with the next access control headers : Access-Control-Allow-Origin, Access-Control-Allow-Headers, Access-Control-Allow-Methods For example in python you can do something like this: def return_200(): return { 'statusCode': 200, 'headers': { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET,HEAD,OPTIONS,POST,PUT', 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, Authorization', 'Content-Type': 'application/json' }, 'body': json....

December 9, 2024 · 1 min · Alex Popescu

Deploying docker image to AWS Fargate in GitHub

Let’s deploy a docker image to AWS ECR and further to AWS Fargate. If you don’t have docker installed, now is the time to do it. GitHub Action YML: Create a workflow named main-aws.yml, for example as: name: Deploy to Amazon ECS on: workflow_dispatch: env: AWS_REGION: eu-central-1 # set this to your preferred AWS region, e.g. us-west-1 ECS_SERVICE: test-svc # set this to your Amazon ECS service name ECS_CLUSTER: test-fargate-dev # set this to your Amazon ECS cluster name ECS_TASK_DEFINITION: ....

December 9, 2024 · 5 min · Alex Popescu

PostgreSQL Web UIs in docker

Let’s install and configure PgHero and PgAdmin4 in docker to connect to the databases deloyed in the previous post. If you don’t have docker installed, now is the time to do it. PgHero: Create the config for PgHero pghero.yml : databases: database1: url: postgres://dummy:123456@10.0.0.3:5432/postgres database2: url: postgres://dummy:123456@10.0.0.4:5432/postgres And run the docker command to start it: docker run -it -d -v $(pwd)/pghero.yml:/app/config/pghero.yml -p 8080:8080 ankane/pghero If everything is ok, you should see:...

November 25, 2024 · 1 min · Alex Popescu

PostgreSQL Replication and Loadbalancing

Create 3 servers on the cloud of choice. This is a diagram of the servers: Node 1 On Node 1 we install postgres, start the postgresql service and add the port to firewall: sudo apt install -y postgresql sudo systemctl enable postgresql sudo systemctl start postgresql sudo systemctl status postgresql sudo ufw allow from 10.0.0.0/16 to any port 5432 Next, we open psql to create the replication user: sudo -u postgres psql CREATE USER ruser REPLICATION LOGIN CONNECTION LIMIT 3 ENCRYPTED PASSWORD 'rpassword'; CREATE USER dummy WITH SUPERUSER PASSWORD '123456'; We should open /etc/postgresql/14/main/pg_hba....

November 17, 2024 · 10 min · Alex Popescu