Posts

Showing posts from September, 2024

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([         '