This project is an example serverless function that can be used to power a PHP based Alexa Skill, running on AWS Lambda, to fetch the next bus times from a number of configured bus stops (using the TransportAPI).
npm install serverless -g
docker run --rm -v $(pwd):/app composer/composer install
sls invoke local --function nextBus
NOTE: You will need php 7 installed locally. Not ideal, but necessary without avoiding this and using docker for local testing instead.
serverless config credentials --provider aws --key AKIAIOSFODNN7EXAMPLE --secret wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
sls deploy
Choose alexa skills kit.
Create a new skill, applying the invocation name "bus timetables". Insert ARN of AWS Lambda we just created. Intent not necessary at this stage, as this basic skill only does one thing, and happens on the launch request.
"Alexa, open bus timetables."
If you need different compiler flags or dependencies you will need to recompile PHP.
To do this, we have to compile the PHP 7.1.2 with statically linked libraries:
sh buildphp.sh
The default is to use the PHP 7.1.2 branch to compile the PHP binary.
To switch the PHP version you can set the branch PHP_VERSION_GIT_BRANCH parameter in buildphp.sh
line 8.
One of the easiest ways is to find your bus stop on OpenStreetMap. Clicking on the stop should reveal data including the all important naptan:AtcoCode
. This is the value you want to use.
From experience (examining bus stops by First Leeds), this tends to just look like the SMS code but with an extra 0. You might be able to guess the ATCO code if data is not readily available on OpenStreetMap.
Alternatively, you can view the full data set from DfT here.
Huge thanks to Robert Anderson for piecing together the serverless framework template that this PoC is based on.
- https://serverless.com/
- http://blog.zerosharp.com/the-serverless-framework-and-php/
- http://blog.gaiterjones.com/amazon-alexa-php-hello-world-example/
- https://github.com/nomisoft/PHP-Alexa-Helper
- https://github.com/awspilot/aws-lambda-php-template
- https://github.com/dannylinden/aws-lambda-php
- https://github.com/ZeroSharp/serverless-php