Posts

How to use aws-lambda-python docker image with example in VSCode for local development

Image
Docker image: https://hub.docker.com/r/amazon/aws-lambda-python This docker image lacks working example on how to use. If you just want to test your lambda with this image locally, please read on. Let's assume the following: Your script is called `my_python.py` The function in this file that you want to execute is called `lambda_handler` Here is the docker command (I'm using windows): docker run --rm \ -p 9000:8080 \ --mount type=bind,src=/c/projects/my_lovely_proj,target=/var/task \ amazon/aws-lambda-python \ my_python.lambda_handler Brief explanation on above: --rm : Remove the container after terminating the script (i.e. Ctrl + C in command line).  So you don't need to run `docker stop <container_id>` and `docker rm <container_id>` -p 9000:8080: map the port of local machine 9000 to container port 8080.  This is super important and will be explained later. --mount: Mount the dir to /var/task in container.  All lambda script will be executed in this /var/task

Add WordPress Admin User via Database 2024 (and onwards)

If you are trying to add a user (probably admin), not using UI but via database directly.  Here is what you did. Refer to the following article to add a user to DB https://hk.godaddy.com/en/help/create-an-admin-user-in-the-wordpress-database-27023 (Recommended) https://help.one.com/hc/en-us/articles/17467509114385-How-to-add-an-Admin-User-to-the-WordPress-database https://wpengine.com/support/add-admin-user-phpmyadmin/ They are all talking about same steps, so just pick one and follow.  In case if you don't understand first article, read the next one and so on. Remember, if you are updating existing DB to use new prefix, you need to manually (or via SQL) update all table name to use your prefix. For example, if original prefix is 'wp_', and you want to change it to "my_lovely_", you need to update all table names, like "wp_posts" > "my_lovely_posts". Here is the missing steps:  Thanks to my colleagues, you also need to update {prefix}_optio

Nginx HTTP2 directive old vs new test result

 The nginx "http2" directive appended after "listen" is deprecated since 1.25.1. Let's see if Nginx will start under old and new version if we put this directive incorrectly Nginx after v1.25.1 server {     listen 80 http2;  # Work, but will issue deprecated warning during start     http2 on; ... } Nginx before v1.25.1 server {     listen 80 http2;       http2 on; # Not work, issue error: unknown directive http2 ... } Conclusion: - Appending http2 in Nginx latest version is OK, even if the the correct directive is `http2 on;` - Do not use standalone `http2 on;` on unsupported Nginx version, it will fail to start. Hope it helps someone.

艾勒里日本大阪,京都,奈良遊記 - 202310

這是想花一點點時間記錄下這次日本之行的想法. 這個標題與我在FB的相簿相同,我就不相信會有人用我FB相簿的標題搜尋這篇文章,我想肆無忌憚地想說什麼就什麼。 先說一些我來之前的想法: 這次會來日本全是巧合。 是因為公司年度晚會被抽到去日本大阪,才會有機會去的。 其實我當下想,是不是能賣出去? 但是,想我做了40多年人以來,好像還沒有機會自己一個人去這麼遠的地方,就想試試。 失敗了也無妨,而且到執筆之時,還不算什麼失敗的。 而且,我妹也能自由行了,做哥哥的怎麼也不能落後。連我妹也做到的事,做哥哥的都做不了那很蠢。 所以再三想過後,還是決定去。因為我覺得,或者有機會在想法上和思考上突破。 雖然很老土,但我還是相信,「讀萬卷書,行萬里路」這句話。 但我仍不想去 旅行規劃: 我在3月左右抽到,但從5月規劃到10月出發前夕,我只有一個念頭: 「好X煩」 沒錯,從一開始規劃路線,到參考不同的Youtube影片,到看Google Map到火滾,都覺得好煩。 主要原因是:日本的鐵路路線「太複雜」。 但後來我想想,為什麼會覺得複雜,那是因為我一開始就想把握整個日本鐵路圖。 因為想要消化/吸收和了解的資料太多,腦袋轉不過來,才會覺得超麻煩。 但反過來想,用以往的方法:倒過來規劃,並只思考特定路線,排除所有與此路線無關的資料,那會簡單得多。 這是經過大概2-3個月在資料/影片堆中挣扎得出的結論。 感悟:試試從目標著手,反過來思考就好。以前我用此方法在IT行業處理過很多問題,在旅行上也可以。 但我仍然不想去。所以只能提醒自己,這是賺取經驗值,不會讓人家看不起的經驗。 我契妹說去旅行是放鬆的,如果讓自己很緊張那不如不去。 但若要放鬆,那為什麼要花錢去旅行,我不喜歡享受,放鬆的話我更喜歡宅在家。或者不花錢去看看某些地方也可以。 我一直覺得,為了放鬆而去花錢旅行不會是我喜歡/想做的事。 當然,若是為了擴闊眼界,倒沒所謂。 但我,沒旅行這個興趣。 這裏要多謝我的好契妹。 酒店和大概的行程是她提供,我再選擇的。 這次她幫了我不少。她也知道我不想去。但仍很支持我。所以想在這裏多謝她這位超級聰明無敵美麗可愛的好契妹。 嗯,也是別人家的老婆,和3位孩子的媽媽 10月中,出發

Cannot connect to MySQL from PHP(Permission Denied), even if commandline or other programs works

If your PHP code (e.g. adminer) cannot connect to your MySQL database (Error: Permission Denied), yet you can connect successfully via other program, like HeidiSQL or even command line, this is for you. Reference:  https://serverfault.com/a/667930/253676 It said even if you have SELinux disabled, Apache server still cannot connect to MySQL Noted what I wrote: Apache cannot connect to MySQL So you need to run (either one, not both): Permanent: `setsebool -P httpd_can_network_connect_db on` Temporary: `setsebool httpd_can_network_connect_db=1` Then you tried again, you should be fine.

[Fix] XAMPP Apache2: 'AH01630: client denied by server configuration'

 If you are seeing this error, read this answer first : Then you just need to update your httpd-vhosts.conf like this, and restart Apache.  Hope it helps someone. NameVirtualHost *:80 <VirtualHost *:80>     DocumentRoot "C:/projects/my_project/"     ServerName my_project .local     ServerAlias *. my_project .local     ErrorLog "logs/ my_project .local-error.log"     CustomLog "logs/ my_project .local-access.log" combined     <Directory "C:/projects/ my_project /" >         Options Indexes FollowSymLinks         AllowOverride All         # apache 2.2         Allow from all         # --New way of doing it - apache 2.4         # Require all granted     </Directory> </VirtualHost> <VirtualHost *:80>     DocumentRoot "C:/xampp52/htdocs/"     ServerName mainproject.local     ServerAlias *. mainproject .local     ErrorLog "logs/ mainproject .local-error.log"     CustomLog "logs/ mainproject .local-

Solved: VirtualBox new disk space not available even after resize

Image
Why making things so complicated? Environment: Oracle VirtualBox Ubuntu Linux 22.04 Server (i.e. CLI only) Problem: In VM I original have 15 GB HD, and extend it to 30GB, but in VM I still see 15GB. Solve: First, make sure you are following this tutorial to add and extend your disk space. But the above tutorial is not completed. You also need to read this post to get an idea on what is missing. But even if you read that, that post is not clear at all. So follow this: Run `lsblk` first to understand what you have In my case, my ubuntu is installed in /dev/sda3, which "said" it has 30GB, but only 14GB is mount to / Run `vgs` to see more Start resize: First, run `pvresize /dev/sda3` to resize your partition Then you run `lvresize -L <SIZE>GB <VG_NAME>/<LV_NAME>` to resize volume group and LV_Name But how to find SIZE, VG_NAME and LV_NAME? SIZE = 30GB To find VG_NAME and LV_NAME, run `sudo lvdisplay` Now you can complete this command, run  `sudo lvresize -L 30