Posts

AWS cloudfront + S3 result in 503 error - S3 to serve HTML

Image
 Quick note: If you are serving HTML/CSS/JS/Any image files via AWS S3 with Cloudfront, but got 503 error, here is one way to solve: Simply put: In Viewer request, set cloudfront function to "serve-html-by-s3" Set Viewer repsonse to "No association" Setting Viewer response to value other than "No association" will result in 503 error. Hope it helps someone.

PHP 5.6 way to send AWS SNS topic message

This is an example PHP 5.6 script to send AWS SNS topic message. The architecture and assumption are as follow: Architecture: SNS (FIFO) -> SQS(FIFO) -> Lambda Only FIFO SNS can connect to FIFO SQS. Standard SNS cannot publish to FIFO SQS. Assumption: This script is executed in an EC2 instance. Assigned an AWS role to send SNS message. Because of above, supposed that there is no need to use Credential when creating SnsClient object. As the OS and PHP in this EC2 is old, the curl is already outdated. So it set http to false to bypass SSL verification.  Reference here . The $message part is designed for sending email for different vendor. In other words, it would vary in different case. Since SNS and SQS are FIFO, MessageGroupId must be set. It can be any random string, which is used to group message together for sending purpose. Here is the code <?php  require_once 'vendor/autoload.php'; use Aws\Sns\SnsClient; try{     $snsClient = new SnsClient([         '

NodeJS dotenv .env: Which comes first? .env or environment var defined in Cloudformation?

As of this writing, in short: Cloud formation comes first. If you are using dotenv (.env), and you define the same variable as in your cloud formation template, cloud formation template will override the value in your .env

Laravel 11 cannot connect to Redis (serverless) - Checking points

Image
 If you are having trouble connecting to Redis server (usually AWS, other cloud platform applied as well), here are some of my tested ideas to check. All points are valid as of this writing, under Laravel 11 (Using Nginx + php-fpm, all dockerize), and build/executed in AWS ECS As of this writing(5 Jul 2024), please use REDIS_CLIENT = phpredis.  predis did not work.  It will not able to connect to your AWS redis (serverless) server.  Yet it works if you setup in your local development In my setting, REDIS_CLUSTER = rediss (double s), before that default value is `redis` There are 3 array sections: default, cache and session default: according to this git comment , this is for "normal" server.  I guess it means standalone server.  Which means the settings under default is for normal server. cache: These settings are for cluster.  I found that serverless = cluster. session: These settings are for sessions, if you are saving session data in redis In other words, you cannot assume

How to clone MySQL database using SQL within same server?

Here is how to clone MySQL/MariaDB within same server. Core principle: use `Create TABLE <new_db>.<table_name> as select * from <old_db>.<table_name>`, and do it for all tables. If you have too many tables, you use the following SQL to generate a list of SQL. Steps: Use `CONCAT` to create SQL by selecting all tables from DB Get a list of `Create Table` and then run it all. SELECT CONCAT('CREATE TABLE my_database.20240510.', table_name, ' AS SELECT * FROM my_database.', table_name, ';') FROM information_schema.tables WHERE table_schema = 'my_database'; CREATE TABLE `my_database.20240510`.change_password_history AS SELECT * FROM my_database.change_password_history; CREATE TABLE `my_database.20240510`.children AS SELECT * FROM my_database.children; CREATE TABLE `my_database.20240510`.failed_jobs AS SELECT * FROM my_database.failed_jobs; CREATE TABLE `my_database.20240510`.interests AS SELECT * FROM my_database.interests; CR

Laravel 11: Encrypted string length for database (MySQL)

In Laravel, as of this writing, the encryption string length different for different length of source string. Here is the list Encrypted string length: 200 for 1 - 15 chars Encrypted string length: 228 for 16 - 31 chars Encrypted string length: 256 for 32 - 47 chars ... In other words, for every 15 chars increases in source string length, the encrypted string length increased 28 chars accordingly. Which also means: if your table column with set to 200, it stores maximum 15 chars of source string length. Hope it helps.