Pragmatism in the real world

Step debugging sphinx-build in PyCharm

I've been trying to solve an issue with the rst2pdf Sphinx extension which allows you to use rst2pdf to create a PDF of your Sphinx documentation rather than using Sphinx's default pdfTeX builder. In order to understand what was happening, I really wanted to inspect variable at certain stages of the process, which is easiest with a step debugger. As I already use PhpStorm for step debugging PHP, I fired up PyCharm and worked out… 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.

Keyboard shortcut to Save as PDF on Mac

I regularly print to PDF on my Mac, This is done from the print dialog by selecting Save as PDF from the drop down in the bottom left of the dialog which is a bit of a pain to get using the mouse. I recently discovered that I could create a keyboard shortcut to make this much easier. In System Preferences -> Keyboard -> Shortcuts -> App Shortcuts you can create a keyboard shortcut to… continue reading.

Extracting the base name of a file in Bash

I have a handy bash script that transcodes videos using Don Meton's video_transcoding tools. This script was written in a hurry and one limitation it had was that it re-transcoded any source file even if the output file already existed. The script looked like this: #!/usr/bin/env bash readonly source_dir="${1:-MKV}" readonly output_dir="${2:-MP4}" for file in "$source_dir"/*.mkv; do ./transcode.sh "$file" "$output_dir" done What it should do is only run transcode.sh if the output file doesn't exist, so… 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!

Slim 4 Cyclomatic Complexity

There's not much wrong with Slim 3; lots of people are using it very successfully producing APIs and websites of all kinds. For Slim 4 the main goals have been to support PSR-15, make it easier to use your own PSR-7 implementation, improve error handling and remove assumptions that look magical if you don't know they are there. The latter one is the most important to me, personally! Secondarily, Pierre has concentrated on making Slim's… continue reading.

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.