A photo archive web app including API, storage and face detection using serverless framework
A photo archive using serverless framework. This is a work in progress (see issues for planned enhancements - help welcome!). It's a great app for learning and trying out AWS services and it is useful for managing your own photos.
Currently the fotopia serverless project includes:
yarn global add serverless
You can deploy from your computer using the serverless CLI. However I recommend using CI/CD (See next section).
I'm currently having an issue with deploying from dev machines. Even when I use the exact Lambda node version - 8.10.0 - the Sharp module doesn't build correctly and the thumbs lambdas fail. When deploying via CI/CD which uses ubuntu, there is no issue.
For proper deploying - it's best to use CI/CD as you're certain to use the right settings (eg node version) every time. The
.travis.yml file does the following steps on commit:
npm install -g serverless
sls deploy -s devDeploy to dev stage environment
yarn functional-devRun functional tests against the dev stage stack
sls deploy -s prodDeploy to prod stage environment
Sometimes you need to remove your stack and start again. If you are using the
travis.yml spec this is as easy as adding 'redeploy' to your commit message or travis-ci trigger.
travis.yml uses conditionals to pick up branch and commit info and decide what build to run. I use an alpha branch to try out experimental stuff.
NAME_SPACE=identifier-to-make-s3-buckets-unique # eg my-identifier which becomes fotopia-web-app-my-identifier-prod AWS_ACCESS_KEY_ID=<aws access key> AWS_SECRET_ACCESS_KEY=<aws secret key> CUSTOM_DOMAIN_DEV=dev-api.yourdomain.com # optional if you don't want to use the serverless-domain-manager plugin CUSTOM_DOMAIN_PROD=api.yourdomain.com # optional if you don't want to use the serverless-domain-manager plugin TEST_USER_NAME=YourTestUserName TEST_USER_PWD=Y0urTestP*ssword FOTOPIA_GROUP=my-group # a string used as dynamodb global index key to allow queries across all users photos. in future this will allow for a simple way to have separate groups in one fotopia instance
If you are setting up a test user for a new stack or a new user each time then, remove
TEST_EXISTING_USER and use:
TEST_USER_EMAILemail@example.com TEST_USER_NAME=YourTestUserName TEST_USER_TEMP_PWD=TempPwd123! TEST_USER_PWD=PermPwd456!
Local mocking of AWS services is fraught. I've stopped doing it as the upkeep is not worth the value I get. I prefer to deploy straight to cloud after thorough TDD locally.
yarn test- unit tests
yarn test-watch- unit tests watcher
npx tape -r ts-node/register -r babel-register './fotos/delete__test__.ts' | npx tap-spec(need to globally install npx)
Things will go wrong - with AWS services pretty much everything can be configured so there are a lot of moving parts. Guiding principles are:
Some modules (Sharp I'm looking at you) don't work in AWS Lambdas unless installed via the exact same Node version. So make sure you are always on v8.10.0 or always rely on your CI tool to deploy.
Yes! Do it.