API Gateway & ‘Single’ Quotes

Very quick post to explain something that has bothered me for longer than it should have today and it needn’t bother anyone else.

When you use API Gateway and Lamba you will likely use the standard ‘Body Mapping’ function that passes through everything in the request to the Lambda function. It parses url parameters and delivers it to Lambda as a nice JSON object you can quickly make use of.

There is one snag however, it doesn’t like single quotes. The minute you pass in a url parameter with a single quote you will get this error:

{"message": "Could not parse request body into json: Unrecognized character escape \'\'\' (code 39)\n at [Source: [B@7d54c1f5; line: 7, column: 27]"}

Ugh you think, it was all working so nicely. Well there’s a simple fix. Replace your body mapping template with this one, actually there are only two line changes to the default one.

## See http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
## This template will pass through all parameters including path, querystring, header, stage variables, and context through to the integration endpoint via the body/payload
#set($allParams = $input.params())
"body-json" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
#set($pval = $util.escapeJavaScript($params.get($paramName)).replaceAll("\\'","'"))
"$paramName" : "$pval"
"stage-variables" : {
#foreach($key in $stageVariables.keySet())
"$key" : "$util.escapeJavaScript($stageVariables.get($key))"
"context" : {
"account-id" : "$context.identity.accountId",
"api-id" : "$context.apiId",
"api-key" : "$context.identity.apiKey",
"authorizer-principal-id" : "$context.authorizer.principalId",
"caller" : "$context.identity.caller",
"cognito-authentication-provider" : "$context.identity.cognitoAuthenticationProvider",
"cognito-authentication-type" : "$context.identity.cognitoAuthenticationType",
"cognito-identity-id" : "$context.identity.cognitoIdentityId",
"cognito-identity-pool-id" : "$context.identity.cognitoIdentityPoolId",
"http-method" : "$context.httpMethod",
"stage" : "$context.stage",
"source-ip" : "$context.identity.sourceIp",
"user" : "$context.identity.user",
"user-agent" : "$context.identity.userAgent",
"user-arn" : "$context.identity.userArn",
"request-id" : "$context.requestId",
"resource-id" : "$context.resourceId",
"resource-path" : "$context.resourcePath",
"radiobase" : "now-playing-submit"

Read More

Alzheimer’s light therapy

An article published in New Scientist today suggests that light therapy may help in the treatment of Alzheimers. There are many caveats around it, it’s only been tested in mice and only seemed to benefit the visual cortex, not other areas of the brain. So the chances of it working on humans are perhaps slim, however the experiment was rather straight forward and low risk. It just used a 40hz light source which is easily recreated on a computer, so I thought it would be cool to build a little page that simply generates a 40zh flash from black to white. If you suffer from Epilepsy then it’s obviously a bit risky so I put a warning on the page before it starts. It’s only roughly 40hz as the timer in the browser isn’t all that accurate – so for that reason alone this is probably useless.


Read More

Friday Lunchtime Playlist

Well I’ve had a month off to collect my thoughts, decide if I want to Vote Remain or Vote Leave, do the hokey cokey, go to a few weddings and do some running up REALLY massive hills. Anyway, The Friday Lunchtime Playlist is back!!! Yay! ‪#‎NewMusicFriday‬

This week featuring music from these great people/bands…
MontaigneBecause I Love You
DROWNERSConversations With Myself
of Montrealits different for girls
Death Valley GirlsIm A Man Too
Earth HeartHomesick
Savoy MotelSouvenir Shop Rock
Ethan BurnsHomeward
Smith & ThellStatue
Moons Of MarsTake It Easy
Free SwimThe Slingshot Maneouvre In Apollo 13
Goon SoulWhos Gonna Love Me
Lake JonsIn Time
John SplithoffSing To You
Jim Caesar5050
FLUIR & Jesse MarantzIve Gotta Have You

Read More

Friday Lunchtime Playlist

In many ways its been a horrible week – we’ve lost some legends of both comedy and music. The great Victoria Wood and the music legend Prince! So this week we kick off the playlist with a nod to Prince from an of Montreal cover of Computer Blue.

This weeks playlist is as follows:

of Montreal – Computer Blue
The Perks – Enough Of This Place
THANKS – Dizzy
Tancred – Bed Case
Fragile Creatures – Fragile Creatures
Love in October – Teenage Evolution
Jerry Williams – Mother
Hanni El Khatib – “Baby’s OK”
Pretty City – Running Around
Magic Potion – “Cola Boyys”
Carnival Youth – Surf
Weaves – Candy
The Academic – Chasers
Marsicans – Swimming
Spring Break – Degenerative Eloquence
Sheer Mag – Can’t Stop Fighting
ELEL – Animal
Two Year Vacation – Love Will Come Back To You

Read More

Homemade Radio

Reading this week about the sad demise of Live365 it got me thinking about the hopes and dreams of younger Dave. Younger Dave wanted many things, to travel the world, to drink lots of beer, meet lots of girls and of course – make my millions and run a radio station. Some how I was deluded into thinking the last two were interlinked, run a radio station and make a fortune, it was simple. Build something great and the masses will come. It’s a common fallacy, you have the best idea – of course you do, everybody else must think the same as you do, it’s so brilliant! It’s as true now with the multitude of stations/platforms as it was a decade ago.

Older Dave is a little wiser, he knows radio stations don’t attract an audience just by being brilliant, you have to bang on doors, spend money on advertising and build brand awareness. He also knows it’s a lot of work, and as I’ve already alluded involves a lot of money. That’s where Live365 went some way to help new entrants, it provided the infrastructure to get you going. True most of them were tin pot jukeboxes that had few listeners, but still if you had an idea you could get it on the internet for virtually nothing. So I did a bit of hunting around and came across another similar platform, Radionomy, and had a go at creating a station. I already had a catalogue of music from my weekly playlists that would act as a playlist, all I had to do was upload it all, throw in a bit of cheesy production and hey presto young Daves hopes and ambitions would not be completely forgotten.

So an evening or two later and I have a rather basic radio station that’s on TuneIn and soon to be on Pure Connect (the Pure Radio platform). Have I got any listeners, no, of course not, but I knew that. This was born more out of curiosity than any real ambition to make anything proper, but I’ll keep it going as a vehicle to help promote (to one man and his cat) The Friday Lunchtime Playlist – which is slightly more manageable than a fully fledged radio station.

If you fancy a listen you can find it on TuneIn by searching “FLP Radio”

Read More

Friday Lunchtime Playlist

It is week two of trying to get artists to record intro’s (drops) to songs, I think it makes these shows sound a lot better and hopefully from a listener perspective it increases the likelihood they will check out the band more deeply.

Featuring this week, music from : Katy Gunn, Laney Jones, Mass Gothic, Slutface, Weezer, Robert Pollard, argonaut&wasp, SOFI TUKKER, Nat Slater, JUNIOR PROM, Banta, Radiation City, Oscar, exmagician, Get Inuit, kakkmaddafakka, Santigold, Stealth and Melaena Cadiz.

Please LIKE and REPOST on MixCloud, this really helps get the show up the charts 🙂

The Friday Lunchtime Playlist – 2016-01-22 by The Friday Lunchtime Playlist on Mixcloud

Read More

Friday Lunchtime Playlist

Soundcloud is an amazing platform, I love it, it’s where I discover pretty much all my new music. However, for playlists, it has some short comings. You can’t mix tracks together and if an artist removes a track from their profile then so to it vanishes from your playlist. So from now on playlists are being delivered via Mixcloud, it allows for a tiny amount of production, so I can if I want to do some talking -don’t worry, I probably don’t have time for this- but it allows me to smarten it up a bit, make levels consistent and remove any dead air. Anyway, without further rambling, here’s this weeks playlist.

The Friday Lunchtime Playlist – 2015-11-13 by The Friday Lunchtime Playlist on Mixcloud

Read More