Wednesday, March 28, 2018

PHP with docker

A friend asking about a PHP library and I decided to test whether that library is working. But I don't have PHP environment setup (we're Python shop btw). But thanks to docker, that's easy these days.

docker run -it --tty --rm --volume $PWD:/app --user $(id -u):$(id -g) composer require google/apiclient:^2.0

Then we just need to create the script to run, still in the same directory:-

include_once __DIR__ . '/vendor/autoload.php';

$GCSE_API_KEY = "nqwkoigrhe893utnih_gibberish_q2ihrgu9qjnr";
$GCSE_SEARCH_ENGINE_ID = "937592689593725455:msi299dkne4de";

$client = new Google_Client();
$service = new Google_Service_Customsearch($client);
$optParams = array("cx"=>self::GCSE_SEARCH_ENGINE_ID);    
$results = $service->cse->listCse("lol cats", $optParams);

And we can run that script again using docker:-

docker run -it --rm --volume $PWD:/app -w /app php:5.5-cli php cse.php


Tuesday, March 13, 2018

Receiving Email Using SES

There's service like Pawnmail (seem to be down now) that allow you to receive email on your custom domain. But that's a third party and mean adding another one into your trust list.

Since we already using AWS, I'm wondering if it has anything that can receive email. They have SES that usually used to send email. But turn out SES can also receive email. So just add the MX record in your DNS to

Next is to configure the domain and address to receive the email.

The received email need to be forwarded somewhere like to your application for processing but that's overkill. I need something simpler. Here come SNS, Simple Notification Service. So the email can be forwarded to an SNS Topic. From the SNS Topic you can create Subscription that will forward the email to your actual email, finally.

SNS will send the email as JSON so if you received HTML email that will be appear in your inbox as is. But since I can read HTML, that should be fine.