Use Decorator in Python

Let’s grasp the concept of decorator in Python PEP 318 with short snippets. Step 1: Function as a parameter def f1(): print("Called f1.") def f2(f): f() f2(f1) # Called f1 f2 takes a function (object) as a parameter. Step 2: Wapping function def f1(fun): def wrap(): print("Start wrap") fun() print("End wrap") return wrap def f(): print("In function f") f1(f)() ### python test.py #Start wrap #In function f #End wrap Step 3: Use decorator def f1(fun): def wrap(): print("Start wrap") fun() print("End wrap") return wrap @f1 def f(): print("In function f") f() ### python test.

Rust Serverless

Getting started I followed the link. In this page, the author wrote details and it’s very educational. To remind the procedure, I left memo. I really appreciate you, Chuma Umenze :) Hello world code cargo new rust_lambda Cargo.toml: [package] // --- snip --- autobins = false [dependencies] lambda_runtime = "0.2.1" serde = { version = "^1.0", features = ["derive"] } [[bin]] name = "bootstrap" path = "src/main.rs" src/main.rs: use lambda_runtime::{error::HandlerError, lambda, Context}; use serde::{Deserialize, Serialize}; use std::error::Error; #[derive(Deserialize, Serialize, Clone)] #[serde(rename_all = "camelCase")] struct LambdaRequest { full_name: String, message: Option<String>, } #[derive(Deserialize, Serialize, Clone)] #[serde(rename_all = "camelCase")] struct LambdaResponse { lambda_request: LambdaRequest, } fn main() -> Result<(), Box<dyn Error>> { lambda!

Quick Ansible test

This is memo when I want to run simple tasks quickly. Directory. $ tree . ├── ansible.cfg ├── hosts └── test.yml In hosts. [servers] server1.mydomain.com server2.mydomain.com server3.mydomain.com test.yml. - name: test-playbook hosts: servers tasks: - cron: name: "Add a cron when rebooting" special_time: reboot job: "echo $PATH" user: atlex00 ansible.cfg [defaults] host_key_checking = False deprecation_warnings=False Exec: ansible-playbook ./test.yml -i hosts -bD -C

NVM

What’s nvm Node.js Version Manager. Like pyenv in Python. One difference from Pyenv is, you can’t label a name to the environment. package.json manage the libraries. Install nvm Follow the official document. https://github.com/nvm-sh/nvm curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash ..... (simple results) Check. $ nvm --version 0.39.0 $ node Command 'node' not found, but can be installed with: sudo apt install nodejs Install Node.js and switch versions # Current available Node.

Serverless framework - Getting Started with Python

I tried Serverless framework with Python AWS Lambda. Prerequirement Node.js and npm. $ node -v v10.19.0 $ npm -v 7.5.2 Install I created my serverless account with Google SSO. sudo npm install -g serverless Hello world Create a project: $ serverless Serverless: No project detected. Do you want to create a new one? Yes Serverless: What do you want to make? AWS Python Serverless: What do you want to call this project?

Small tip: Multi aws-cli environment

Motivation If you use multi AWS accounts in your work environment, I hightly recommend to configure your “aws-cli profile” so that you can easily change your aws-cli account. The only thing you need to do when you want to change your aws-cli environment is the option --profile. Very simple. How to configure https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html Check under ~/.aws/. You can configure multi profile.

GitLab Runner

Pre-requirement I installed Docker because I wanted to use Docker executor for better isolation of environments. Install GitLab Runner on the server Follow the official manual. https://docs.gitlab.com/runner/install/linux-repository.html On Ubuntu From repo (recommended) curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash export GITLAB_RUNNER_DISABLE_SKEL=true; sudo -E apt install gitlab-runner Check. $ sudo gitlab-runner status Runtime platform arch=amd64 os=linux pid=3163 revision=2ebc4dc4 version=13.9.0 gitlab-runner: Service is running! $ sudo gitlab-runner list Runtime platform arch=amd64 os=linux pid=3172 revision=2ebc4dc4 version=13.

AWS Network for dummy (me)

Reference I found the good slide which contains good figures to understand AWS network. https://de.slideshare.net/AmazonWebServicesLATAM/aws-vpc-fundamentals-webinar Physical location From the slide 10/58. Region consists of multi AZs (Availability Zone) An AZ consists of AZ-a, AZ-b, AZ-c, etc. AZx (x=a,b,c) consists of data centers The latency within the Region is ~2ms. Logical network VPC: A private network like 172.31.0.0/16 across AZs (AZa, AZb, AZc). VPC subnet: Each AZx is assiend a subnet, like 172.

LVM and File System

How to think Linux volume system Here is the coprehensive image from Wikipedia. There are several physical volumes (PVs) in a server. Linux group the physical volumes in a volume group (a VG). Each of PVs contains physical partitions (PPs). We can aggregate the PVs in a logical volume (a LV). On a LV, we can decide a file system (FS). From Linux side, we can mount a Linux directory to the FS.

Cognito - tutorial

First thing you should decide We should decided “User pool” or “Identity pool”. Here is the official blog post about the differences. https://aws.amazon.com/de/premiumsupport/knowledge-center/cognito-user-pools-identity-pools/ In a nut shell, User pools are for authentication (identify verification), and Identity pools are for authorization (access control). I’ll try an User pool. Future scope: integrate with AppSync. Tutorial 1. Create an User pool I followed the link. Very easy. https://docs.aws.amazon.com/cognito/latest/developerguide/tutorial-create-user-pool.html Choose Manage User Pools. Manage User Pools.