Pragmatism in the real world

Dependency injection in Serverless PHP with Bref

When writing PHP for AWS Lambda, Bref is the way to do it. One thing I like about Bref is that you can use PSR-15 Request Handlers to respond to API Gateway HTTP events as documented in the API Gateway HTTP events section of the Bref docs. The request handler is the same as used in PSR-7 micro-frameworks like Slim or Mezzio and can be thought of as a controller action. As such, it's really… continue reading.

PHP Architect: Serverless PHP With Bref, Part 2

Part two of my article on using Serverless PHP using Bref has been published! In part one, I introduced Bref as we wrote a simple "Hello World" application. Part follows this up exploring a more complete serverless application, my Project365 website. This S3 hosted static website is build using a serverless PHP function that connects to the Flickr API to retrieve my my one-photo-per-day images and present them on a single page per year. In… continue reading.

Circular dependencies in AWS SAM Policies

I'm trying to tighten up the policies of my AWS Lambda function so that it only has access to the one S3 bucket that it needed, so I added an S3CrudPolicy with the BucketName referencing the bucket that's defined in the template. The relevant part of template.yaml looks like this: Resources: ImagesBucket: Type: AWS::S3::Bucket Properties: BucketName: !Sub "${ProjectName}-${UniqueKey}-images" ResizeFunction: Type: AWS::Serverless::Function Properties: FunctionName: resize # … Events: CreateThumbnailEvent: Type: S3 Properties: Bucket: !Ref ImagesBucket Events:… continue reading.

Changing the AWS API Gateway response status code in SAM

When creating an API with AWS Lambda and Api Gateway, I discovered that a client request to a given resource with a verb that wasn't supported resulted in an unexpected response. You can see this from this curl command to the /test resource which is only defined for GET: $ curl -i -X PUT https://mh5rwr9q25.execute-api.eu-west-2.amazonaws.com/prod/test HTTP/2 403 content-type: application/json content-length: 42 {"message":"Missing Authentication Token"} Given that I can GET the /Prod/hello resource, I would not… continue reading.

My Bref Makefile

In order to use Bref efficiently, I've developed a Makefile so that I don't have to remember all the various commands required. In particular, looking up the correct parameters to sam package & sam deploy is a pain and it's much easier to type make deploy and it all works as I expect. It looks like this:

PHP Architect: Serverless PHP With Bref, Part 1

I've written a two-part series on Serverless PHP on AWS Lambda using Matthieu Napoli's Bref for php[architect]. Part one has been published in the May 2019 issue and if you're not already a subscriber, you should be! If you just want to learn about Bref though, then my introduction to Bref is available for free, just for you!

Using img2lambda to publish your Serverless PHP layer

This interesting tweet by Clare Liguori came to my attention last week: This new img2lambda tool will take the layers of a Docker container and convert them to AWS layers for use in Lambda. I poked around with Clare's example and updated my lambda-php project in order to understand how it works. I also rewrote my runtime's bootstrap to make it clearer. The clever thing from my point of view is that you can build… continue reading.

Serverless PHP on AWS Lamda

Like, Simon Wardley, I think that serverless computing is an interesting space because the billing is granular (pay only when your code executes) and you don't need to worry about maintaining and provisioning servers or containers. So much so, that I maintain the Open Source PHP Runtime for Apache OpenWhisk which is available commercially as IBM Cloud Functions There are other serverless providers, and AWS Lambda is the market leader, but until recently PHP support… continue reading.