This is a basic Flask application that implements two simple REST methods (GET, PUT) on top of AWS infrastructure.
You will need the below resources configured:
A non-administrative user with the following permissions is required:
-
AmazonEC2FullAccess, AmazonDynamoDBFullAccess
-
In order to pass this role to EC2 instances, your AWS user will need the PassRole permissions. This document shows you how to set it up: Permissions Required for Using Roles with Amazon EC2
-
The EC2 instances need access to DynamoDB. You can use the same role as in step 1, or one with just AmazonDynamoDBFullAccess. Either way, the "Instance Profile ARN" of the role must be entered in the ansible variables file.
- Required packages: ansible, boto, python-virtualenv (if you rather use a virtual env)
AWS credentials of user defined in step 1 must be added to ~/.aws/credentials
- A test dataset is not automatically created. To test the application, create a DynamoDB table and add some data. You can do this on the same machine, with the json files included in this repository:
aws dynamodb create-table --cli-input-json file://create-table.json
aws dynamodb batch-write-item --request-items file://batch-write.json
You will need to run the Ansible scripts on a control machine (laptop or VM)
Verify the variables in ansible/group-vars/variables.yml There is no AMI mapping per regions, so the playbook will only work in eu-central-1 (Frankfurt) region.
To provision the infrastructure:
ansible-playbook -v ansible/playbooks/aws_deploy_playbook.yml
The last output will give you the DNS Name of the Load Balancer on which the application can be tested.
Performing a GET to retrieve the date of birth of a user:
curl -X GET http://devops-challenge-lb-<some_name>.amazonaws.com/hello/John
{
"message": "Hello, John! Your birthday is in 59 days."
}
Changing the date of birth:
curl -X PUT http://devops-challenge-lb-<some_name>.amazonaws.com/hello/John \
-H 'content-type: application/json' \
-d '{"dateOfBirth": "15-12-1976"}'
Checking that the data has indeed changed. This can also be checked in DynamoDB in the AWS console.
curl -X GET http://devops-challenge-lb-<some_name>.amazonaws.com/hello/John
{
"message": "Hello, John! Happy birthday!"
}
ansible-playbook -v ansible/playbooks/aws_destroy_playbook.yml -e state=absent