Skip to content
This repository has been archived by the owner on Dec 10, 2022. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* dev:
  Update Lambda func alias after deploy
  Ensure tests fail on CI if they would return an error
  Fix incorrect AWS access key:
  Supply AWS settings for testing in CI
  Tweak deployment config
  • Loading branch information
tdmalone committed Jan 26, 2018
2 parents 153c034 + 6311ab4 commit 8f35837
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 22 deletions.
61 changes: 42 additions & 19 deletions .travis.yml
@@ -1,34 +1,57 @@
language: node_js
services: docker
node_js: 6.10

env:
global:

- AWS_ACCESS_KEY_ID=AKIAJEF3SOFO6AFQZBTA
- SNS_QUEUE=arn:aws:sns:ap-southeast-2:873114526714:location-events-queue-dev
- LAMBDA_NAME=proximityEventsWebhookParser
- LAMBDA_ALIAS=prod

# AWS_SECRET_ACCESS_KEY
- secure: bKgft7+sCmss0eH93BBhYtLz15MI0kdhLzU1aEbPztQNfWdmv59hduFdB8wa+uBqLMZoZItIq0C17qcQRlVjtsS8m8ekg4tK0OOHkAVuqBnuEKzDL3qmUAQmg5v+8x5FYVKldhixfc29mjA2k1GakG+rbd0qk1YtXj7UJyM2dyVNi6xyVWmDfndWerVTrkwn1j6eBnPmTspChLziLpD1rBJc2kEdIeXlUkDycm9enicVULqn1nwQTU+TwVtgMLTH99p8JX2+fSF/NoUuW+dULYacfurKUUVWSZLWEd7BP3Njm8kyN4LGwMNAn6AjYLUz2HaxJXSPRcSd0OAJ9c/iyRYVUxAlciNwonkuvjem+7qUhjD7RY+dVnTcGRgIv/DlToK4UUY95pMBTlDx8IL3beO3PGqorNZAq7xN85hpwUWmlK3LVZ0hqZh4nvv3sOXi8rU5EBaIocgZyPBPvx8PxfzZ8odFDv8wlre3leSaqofLL+P3eJapKtJ7L50WVQ9Tgp2uWloD8xuGnF+WFZfZBEnjt5gAdKbs9i6BfzpjF0W2Vz5Gj/QT2EMTLoO5PHlq29FOUqCu6RZZqwY+YcWxabcFh4dz6otq9Lra+LgOtQdjoavEeK5nCNd3bVw9JshCMpu7LrEe/Kwz7ZiuNld3seGNQAe+OIHJUxmmZwNNsFw=

install: true
script: yarn test
before_deploy: rm -rf tests package.json *.md

deploy:

on:
branch: master
skip_cleanup: true

# TODO: Also publish to npm.

# @see https://docs.travis-ci.com/user/deployment/lambda/
provider: lambda
publish: true
function_name: "proximityEventsWebhookParser"
region: "ap-southeast-2"
role: "arn:aws:iam::873114526714:role/genericLambdaRole"
description: "Parses and queues webhook events sent by the Proximity Events iPhone app."
runtime: "nodejs6.10"
handler_name: "handler"
access_key_id: "AKIAJVWRHTUGC7RFRHXQ"
secret_access_key:
secure: "hcmnv7X2MoLLiEvYBYFcZk6b3Km8d/IdrcyU4Q2N6ylKB81f3YVzU4xGdv+s2PBiZTtdSqjpO6uno7FBquBJ5k4TVglyba6reOWDCUkCxmv6oh+G7yGJ5p0md4h7lkCT3BuJJ5M936spHQzQMmCWhk27bjXYBMGgTsaiW+JrpIS2Aw2YEjpFcxkcbaVoFEJoY4KCKyWp0PQ8qyoBTR+K63ArO6ZpvJs6cUWuAjpWa2321WrpcetHD9c4Unr7r1oHpq6M7a7VYPirJbKVkj6dqObiWSevxZ1nMNDiqM0vb/nXC8lCQxGtIt7fteyTpV3PxPno8AFUtiM955WiwelSFL/vYVrpr9V+Bitrp2be6Z7OknHjzH7AP7Ej/5k16kTHr9fKdeO1MU4k837tCFlzFwda3biUYupWxmQOhhLGP/zWrdfIe4q6UzQjyOEBhzoFVnh0NMI7AC0h7a0k/AsqobhwK4FuJJCE+8wvzrKFB0Bub7SIspD7NhPx2Wn0oU/kPEIyDTpeY4TllvzM9SDXutYIq/xZjt8+1BsUft8OKm/XzGvdbgK3292OmTDTlDMk0VHxAhkO+HrYEliE03E1WemBmBQyUhd+xoU1bAhAXPHoqBoa8tA3p1BKNvdz+Ww1tAckjunO6g4UnhRj4IV2kNu0I1w8wLnXZ3Frdd8o5fw="
- provider: lambda
publish: true
function_name: $LAMBDA_NAME
region: ap-southeast-2
role: arn:aws:iam::873114526714:role/genericLambdaRole
description: Parses and queues webhook events sent by the Proximity Events iPhone app.
runtime: nodejs6.10
handler_name: handler
access_key_id: $AWS_ACCESS_KEY_ID
secret_access_key:
secure: vBuzR8bhbKvCALvvUm48A7FFhCUUCA4mjhkypnF3/yyLSFZwtgWd+SFiJRldR0Z4B7jnKnMB/YuyTKdGu+HPYABKLBbbO76zvW2CeSPIpiIn+xa9PUsHAROaey/Vf1frUlDFLs4G/2TIBhTVS6a+Fq4Qhco8N9GI9GIJh61sn5J2ard+yyRRO0ch5xiuFMAAY+Y7o4pRxcba5pDy435PK5mUjoGPZioYrONT0VEs+1vL/yc56GBE3fWG93Kxt/xRAxlRvrManSm9gq3ENrnHg4OYu5S3AqaGooA515AJoGCDxoNKJ2oSUJVgfTAksKQ23PeUTie9wlr2LVON0FOtjLVtqTbQZBq5iZJN7Srjwz/f/IJzWqCe2UY+SxJKk+iAiOki7H+MVL7UWKw99rzrGDhhwSxmO8niNz3dV7nsTMUiqfwzJcHyRQZnnvxpeZicJ1QztxDyRZiy8Zia+0I3JrnXHqpRzvaTGfotuBOOQZZdBqYjETbbZXpehsfishbhvnwUFeUTGMNQcEUK8wXTVrPo+/OkuuqsYxAa43jScmrqXr17YSRe6QB8dgbv/XMD3dQEJSeOfqMaAHU6X63sluxXe0WbAqARFpw9qtG0WGtfZYSfeRvRDRryKAqn9jX0GyhqmUgmARq94FVv07d43zsXwba3ssT+PpdZSF43bOU=
skip_cleanup: true
on:
branch: master

- provider: npm
email: tdmalone@gmail.com
api_key:
secure: eZDnL1SGpt0dbOCERxIdHu4Aamyf+kslz4LdZup6bzUg6ehUrrl989z0EZWJka/tU/IXVU00lopTplk0nxgCpuwTHhaCprXRcVnXglgyPyzvSZANHc0YQrgTtEWhLWurK70gj9zzyB7K7s+sLTUrXaMfQW8js4HdhbgFLeWEPXv6M7TWarZwsI5ftYB993TiaaWnhU33Jdn++KuUwuT2FYjRexCiAs5qBwwOuuN5NOEKDt6eyCf97OItUAgEsphJYjCpKesFOZNTARWhSBrkBMZHcqvE7vE2SwJ+LI8Krfe3IbY1FpVHmy62ytbofwYXMvKca0BRx7DovK6F1uunjOxbOD1G/qqbzXU+M5FwrKipgjOMHZUgO4sOCtQBBW7IG2hlMVpuCEqtnCcmlmRQEt8oqqoeQWzld9orKIrx2hPacYRYtYhpu8id2D1OT+IVY5AIT8mmvF2VJlVxX1TFJhKZq/2rd1EbAyAC0ZmSzegwBGArYoFgP7/gN93zHHep5ijBpSEc/DqpJ+FHCW2lhrgL8ag76dHGi5170cCerzhEJKlhpJuOg3naoTHO0SUnahKInJrd/HcN/lg1DRNYZV3W4Y1leo65MtDhM/CxPf9zTWfFkOyFSEMzKbX83CkD3V9w1HVur5GO6SBXoHWkZh99aj6jYnrxJQ+bhL6+npE=
on:
branch: master
tags: true

after_deploy:

# Set a Lambda alias to the most recently deployed version.
- pip install awscli --upgrade --user
- export MOST_RECENT=$(aws lambda list-versions-by-function --function "${LAMBDA_NAME}" --max-items 10000 | node -e "let stdin=''; process.stdin.on('data',(chunk)=>{stdin+=chunk}).on('end',()=>{console.log(JSON.parse(stdin).Versions.pop().Version)})")
- aws lambda update-alias --function-name "${LAMBDA_NAME}" --name "${LAMBDA_ALIAS}" --function-version "${MOST_RECENT}"

notifications:
email: false
slack:
on_start: always
rooms:
- secure: "Vy2JA/ktcFrTVRPzvyQwBh4Q65Hb6lBCbM8RMshxtdSRNSVnctRofN3BJ/QlutYV4EbsWA1jgQaSb3BH0IPF5Mg5MUkv8c1bbW+GbNzMqQG3td2CcjlYF4IVB5Zd+ONqEDQJLglF1z2kwyPh1ZmaWgSvYVc2yhrkqJl3oFdhertAM2sNF7om/KugrCQsjJm+jFhNY62P84jhed7+cmNT6xl9IMN9gZvUqssdvLubmdMTpgz9JBvbn1hAMFI3JjSaHEowAMolnE3mCSlC8aLSjfdX+lKR8vRJGXzURX74eUm7jEM0vHnwn1QrRTUZdUzUl6pP9yaPPDUHNf+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@ A simple AWS Lambda function that 'queues' geolocation trigger events from the [

This function attempts to normalise the data received from the app, because sometimes it sends JSON and sometimes it sends `x-www-form-urlencoded` data, with different fields provided for each. I'm not sure why, but there you go.

Other than that, this func tries to do its job quickly and get out of the way, while providing some error reporting if something goes wrong. I suggest using [cloudwatchToPapertrail](https://github.com/tdmalone/cloudwatch-to-papertrail) or another log monitoring tool to pick up what's happening.
Other than that, this function tries to do its job quickly and get out of the way, while providing some error reporting if something goes wrong. I suggest using [cloudwatchToPapertrail](https://github.com/tdmalone/cloudwatch-to-papertrail) or another log monitoring tool to pick up what's happening.

There are no dependencies to install.

## Tests

Run `yarn test`.

To have tests properly fail (non-zero exit code) when something goes wrong, `export CI=true` first. Otherwise you'll get JSON responses with HTTP error codes instead (made for the AWS API Gateway). For tests to succeed, you'll also need to have exported `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `SNS_QUEUE` with your desired values.

## TODO

* Add setup and installation instructions (or a script to do it)
* Add better tests
* Add timezone handling (using a [geolocation time zone API](https://developers.google.com/maps/documentation/timezone/start)?)
* Make the `Visit:Exit` event dropping configurable
* Use a [reverse geocoding service](https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding) to get the address for form data events
* Don't allow empty fields to be sent through - either remove them or set them to null - as they cause errors if the data is inserted into DynamoDB.
* Publish to npm
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -151,7 +151,7 @@ function exitWithError( error, callback ) {

console.error( error );

callback( null, response );
callback( 'true' === process.env.CI ? error : null, response );
return;

} // Function exitWithError.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -11,6 +11,6 @@
"test-form-data": "yarn _test \"$(cat tests/fixtures/form-data.json)\"",
"test-location-update": "yarn _test \"$(cat tests/fixtures/location-update.json)\"",
"test-visit-exit": "yarn _test \"$(cat tests/fixtures/visit-exit.json)\"",
"_test": "docker run --name lambda --rm -e SNS_QUEUE -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -v \"${PWD}\":/var/task lambci/lambda:nodejs6.10 index.handler"
"_test": "docker run --name lambda --rm -e CI -e SNS_QUEUE -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -v \"${PWD}\":/var/task lambci/lambda:nodejs6.10 index.handler"
}
}

0 comments on commit 8f35837

Please sign in to comment.