1
0
mirror of https://gitlab.com/free_zed/free_zed.gitlab.io.git synced 2024-06-09 11:52:31 +00:00
free_zed.gitlab.io/content/grandpy-bot-zappa-flask-lambda-gitlab-en.md

73 lines
2.5 KiB
Markdown
Raw Normal View History

2019-03-17 22:42:18 +00:00
Title: GrandPy Bot in «serverless» style
Date: 2019-03-16 23:34
Category: Réalisations
Status: published
Summary: Evolution of project 7 realized during the OpenClassrooms course with: Zappa, AWS Lambda & Gitlab-CI/Pages.
2019-03-17 22:42:18 +00:00
Lang: en
Slug: grandpy-bot-zappa-flask-lambda-gitlab
2020-07-21 23:55:23 +00:00
Tags: git, gitlab, devops, flask, dev, zappa, serverless, aws, ci, cd, aws-lambda, python,
2019-03-17 22:42:18 +00:00
This was a [student project][oc] previously hosted on [Github][ocp7]. I updated it to play with:
2019-03-17 22:42:18 +00:00
* [Zappa][zappa]
* [Flask][flask]
* [AWS Lambda][awslmbd]
* [Gitlab-ci][glci]
It is a _robot_ grandfather talking about geographic memories and quoting Wikipedia fetching data over public APIs.
If you can speak French, [have a talk with him][prod] (^_^)
Run yours !
-----------
Need some environment variables to run:
2019-03-17 22:42:18 +00:00
- `EMAIL_ADDRESS` (Nominatim API)
- `MAPBOX_API_KEY` (Mapbox API)
- `GOO_API_KEY` (not used [but needed][issue51])
### Locally:
2019-03-17 22:42:18 +00:00
It works as a simple single-page [Flask][flask] application:
2019-03-17 22:42:18 +00:00
- [fork-it][fork]
- set up a virtualenv: `virtualenv .venv`
- install requirements: `pip install -r requirements.txt`
- run it locally: `python run.py`
2019-03-17 22:42:18 +00:00
### On Gitlab:
2019-03-17 22:42:18 +00:00
Set up a [AWS IAM profile][awsiam] on **your AWS account** and add valid environment variables in `https://gitlab.com/<namespace>/grandpy/settings/ci_cd`:
2019-03-17 22:42:18 +00:00
- `AWS_ACCESS_KEY_ID`
- `AWS_SECRET_ACCESS_KEY`
Push it back and the _CI script_ will:
2019-03-17 22:42:18 +00:00
- put chat code on [AWS Lambda][awslmbd] with the magic of [Zappa][zappa]
- edit [JavaScript][js] with the URL of the _AWS API Gateway_ just updated
- generate the HTML landing page (with a [flask script][genstat])
- deploy statics on _gitlab-pages_ (HTML, images & CSS)
…and _voilà_, have a chat with _GrandPy_ on `https://<namespace>.gitlab.io/grandpy/` (-;
---
Feel free to give feedback using [issues][issues].
[awsiam]: https://github.com/Miserlou/Zappa/blob/master/example/policy/deploy.json
[awslmbd]: https://console.aws.amazon.com/lambda/
[flask]: http://flask.pocoo.org/
[fork]: https://gitlab.com/free_zed/grandpy/forks/new
[genstat]: https://gitlab.com/free_zed/grandpy/blob/master/genstat.py
[glci]: https://gitlab.com/free_zed/grandpy/blob/master/.gitlab-ci.yml
[issue51]: https://gitlab.com/free_zed/grandpy/issues/
[issues]: https://gitlab.com/free_zed/grandpy/issues/new
[js]: https://gitlab.com/free_zed/grandpy/tree/master/static/js/ask.js
[oc]: {filename}/ocp7.md
[ocp7]: https://github.com/freezed/ocp7
[prod]: https://free_zed.gitlab.io/grandpy
[zappa]: https://github.com/Miserlou/Zappa/