Pragmatism in the real world

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.

rst2pdf: back from the dead!

Today marks a momentous day! I've released 0.94 of rst2pdf to PyPI! If you have a need to convert plain text files to PDF, check it out. As the last release, 0.93, was December 2012, I think you could have reasonably assumed that the project was abandoned. So why did I bring it back from the dead?

Setting up IBM Cloud Object Storage

For a little website that I'm writing, I thought that I'd use IBM Cloud Object Storage (equivalent to AWS S3) as I'm generating the pages using OpenWhisk on IBM Cloud Functions. The documentation is quite good if you want to use the website, but is a bit spread all over the place if you're using the command line, which is how I do things. As Cloud Object Storage is a bit of a mouthful, I'll… continue reading.

Keyboard control of macOS notification alerts

I use Apple's Reminders app to remind me about things that I need to do. It has the useful feature of syncing across my Mac, iPad and iPhone and I can add to it via Siri in my car. When I am notified on my Mac, a notification alert appears with two buttons: Complete and Later. Clicking Later offers a set of options to dismiss the alert and have it reappear in 5 minutes, in… continue reading.