New PHP AWS Serverless GitHub Repositories

New PHP AWS Serverless GitHub Repositories

To tell you the truth, I've been holding onto this idea for a while that the best way to send a text message with AWS is to use Twilio.

I had a project to send texts some time ago. Twilio was just so much easier to use for texts and emails than AWS. So I've been quietly avoiding using SNS for a while.

Which is why I made a special point that my first real Lambda project would involve SNS.

I just finished my first real Lambda project. There were two Lambda deployments: one for my simple form, and one to send text messages selected in that form.

Having already figured out how to render Laravel Framework's Blade templates on its own, without launching an app; having figured out how to do this in a Lambda
function; and, having published two open source repos to GitHub with this code, I was able to focus on SNS.

Coming into SNS cold, learning from the ground up, I spent a week or so venturing into my AWS console, watching videos, reading a lot of articles, poring over AWS and Serverless Framework docs. I played with code a lot, executing it locally, and deploying to Lambda via the Serverless Framework, seeing what the results were in my browser and in the AWS console.

There are a lot of code examples for Lambda written in its native languages. A lot of articles. A lot of videos. But there are not a lot of code examples for Lambda written in PHP. A confirmation of what I already experienced. I intended to publish code samples of my PHP Lambda functions after I got my forms working in Lambda. After the fact.

Because my initial experience with SNS was not so wonderful, I decided that I was not going to worry about publishing code samples. It was enough to get my own code working, to understand this aspect of AWS. I should spend my time going down whatever rabbit hole I find myself in, take extra time reading docs, and not worry about publishing sample code right off the bat. Which I did. However, I changed my mind!

I changed my mind because I knew I was going to publish code samples based on my forms anyways. I created a local repo only, and put code in there alongside my Lambda forms code. It was great playing with both sets of code at the same time. One set of code was "anything goes", and the other set of code was formal. Going back-and-forth was a great exercise.

One of the things that came out was my not being clear about sending AWS credentials via the Serverless Framework in local development, and Lambda getting permissions to use other AWS services. To help me understand this stuff, and to share these steps with you, I did an article about it. With things chronicled, I standardized my code sample, and my own Lambda code, to one way of doing credentials, which really helps  readability.

Right from the get-go, I assumed that the way to send a text message in SNS is to create an SNS Topic, and then an SNS Subsription to that Topic. Which you can. When I realized that I could send an SMS via a Topic-less SNS, I already had the code that creates the Topic and Subscription figured out. So I put that in my code sample repo. There is also a code sample for sending a text message in a Lambda function via SNS without an SNS Topic.

I was curious about sending emails as well within a Lambda function. So I tried out SES with Lambda. I included a code sample for SES in my repo.

For things that came up along the way, such as the SES "sandbox", I added comments to my code, or noted it in my README's.

I added README.md's Amazon implements something called an email "sandbox", which I note in my sample code. For stuff like this, I comment my code, and/or mention it in my readme's.

My new serverless repos are at https://github.com/lasallesoftware-serverless.