A python api hosted on aws lambda built using the flask/serverless frameworks which persists data to an aws s3 bucket. An AWSCodePipeline is setup to provide continuous testing/integration.
API URL: https://3z6ahlrgci.execute-api.eu-west-2.amazonaws.com/dev
The following endpoints are exposed:
- /api/user/new -> create new user
- /api/user/all -> return list of all stored users
User data must be in JSON format and follow this schema:
{
'userId': <your_user_id_here>
'name': <your_name_here>
}
AWS Account
Python 3.6^ - get the latest here
Node - get the latest here
NPM:
$ npm install npm@latest -g
Serverless Framework:
$ npm install -g serverless
To setup serverless aws credentials: (guide here)
$ serverless config credentials --provider aws --key <your_key_here> --secret <your_secret_here>
clone the repo, then:
$ cd flask-api
$ npm install
$ pip install -r requirements.txt
$ serverless deploy
$ sls wsgi serve
$ python3 -m pytest -v
Posting correctly formatted data to api running on AWS
- More comprehensive error handling
- Dedicated release pipelines (dev, staging and production)
- Run app locally using local aws s3 mock
- Add remaining CRUD routes (delete, update)
- Automate integration tests
- Validate data inputs
https://serverless.com/blog/flask-python-rest-api-serverless-lambda-dynamodb/
https://scotch.io/tutorials/build-a-restful-api-with-flask-the-tdd-way
https://blog.sicara.com/deploy-serverless-rest-api-lambda-s3-aws-2cf99b8f34ae
The AWS docs - https://docs.aws.amazon.com/
The Serverless docs - https://serverless.com/framework/docs
https://medium.com/@hmajid2301/testing-with-pytest-mock-and-pytest-flask-13cd968e1f24
https://stackoverflow.com/questions/53809090/codebuild-does-not-upload-build-artifact-to-s3 - super helpful!!!
https://dzone.com/articles/boto3-amazon-s3-as-python-object-store
AWS CloudWatch logs were very useful for debugging deployed code