├── .gitignore ├── README.md ├── ansible.cfg ├── ec2_vars └── OpenFaaS.yml ├── provision-OpenFaaS-ec2.yml ├── provision-OpenFaaS-ec2 └── tasks │ └── main.yml └── roles ├── docker └── tasks │ └── main.yml ├── git └── tasks │ └── main.yml └── openfaas └── tasks └── main.yml /.gitignore: -------------------------------------------------------------------------------- 1 | provision-ec2 2 | ec2.ini 3 | ec2.py 4 | *.sh 5 | .vscode 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenFaaS-AWS 2 | 3 | Functioning but Work-in-Progress Ansible Playbook to instantiate a single VM in AWS and deploy OpenFaaS to it. Currently it does require some configuration via the AWS portal to set up security group (SG) rules, obtain your keypair, etc. These are typically one time configurations, so once configured the playbook can perform repeat runs without any changes. 4 | 5 | Requires Ansible and Boto to be available. Once available let boto know your account details: 6 | 7 | ```sh 8 | $ touch ~/.boto 9 | ``` 10 | 11 | Add your credentials to `~/.boto`: 12 | 13 | ```ini 14 | 15 | [Credentials] 16 | AWS_ACCESS_KEY_ID= 17 | AWS_SECRET_ACCESS_KEY= 18 | 19 | ``` 20 | 21 | Pick a machine size & region, and obtain your SG / subnet / keypair details from the AWS portal and complete `ec2_vars/OpenFaaS.yml` accordingly. 22 | 23 | Run the playbook: 24 | 25 | ``` 26 | ansible-playbook -i localhost, -e "type=OpenFaaS" provision-OpenFaaS-ec2.yml 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | host_key_checking=False 3 | -------------------------------------------------------------------------------- /ec2_vars/OpenFaaS.yml: -------------------------------------------------------------------------------- 1 | ec2_keypair: "" 2 | ec2_security_group: "" 3 | ec2_instance_type: "t2.medium" 4 | ec2_image: "ami-785db401" 5 | ec2_subnet_id: "" 6 | ec2_region_URL: "ec2.eu-west-1.amazonaws.com" 7 | ec2_region: "eu-west-1" 8 | ec2_tag_Name: "OpenFaaS" 9 | ec2_tag_Type: "OpenFaaS" 10 | ec2_tag_Environment: "production" 11 | -------------------------------------------------------------------------------- /provision-OpenFaaS-ec2.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | connection: local 4 | gather_facts: false 5 | user: ansible 6 | pre_tasks: 7 | - include_vars: ec2_vars/{{type}}.yml 8 | roles: 9 | - provision-OpenFaaS-ec2 10 | 11 | - name: Configure the new instance 12 | hosts: OpenFaaS 13 | gather_facts: false 14 | remote_user: ubuntu 15 | pre_tasks: 16 | - name: 'install python2' 17 | raw: sudo apt-get -y install python-simplejson 18 | roles: 19 | - git 20 | - docker 21 | - openfaas 22 | become: true 23 | 24 | -------------------------------------------------------------------------------- /provision-OpenFaaS-ec2/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Provision EC2 Box 3 | local_action: 4 | module: ec2 5 | key_name: "{{ ec2_keypair }}" 6 | group_id: "{{ ec2_security_group }}" 7 | instance_type: "{{ ec2_instance_type }}" 8 | image: "{{ ec2_image }}" 9 | vpc_subnet_id: "{{ ec2_subnet_id }}" 10 | region: "{{ ec2_region }}" 11 | instance_tags: '{"Name":"{{ec2_tag_Name}}","Type":"{{ec2_tag_Type}}","Environment":"{{ec2_tag_Environment}}"}' 12 | assign_public_ip: yes 13 | wait: true 14 | count: 1 15 | register: ec2 16 | 17 | - add_host: name={{ item.public_ip }} > 18 | groups={{ec2_tag_Type}},tag_Environment_{{ec2_tag_Environment}} 19 | ec2_region={{ec2_region}} 20 | ec2_tag_Name={{ec2_tag_Name}} 21 | ec2_tag_Type={{ec2_tag_Type}} 22 | ec2_tag_Environment={{ec2_tag_Environment}} 23 | ec2_ip_address="{{ item.public_ip }}" 24 | with_items: "{{ ec2.instances }}" 25 | no_log: True 26 | 27 | - name: Wait for the instances to boot by checking the ssh port 28 | wait_for: host="{{ item.public_ip }}" port=22 delay=30 timeout=60 state=started 29 | with_items: "{{ ec2.instances }}" 30 | no_log: True -------------------------------------------------------------------------------- /roles/docker/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: 'install Docker' 3 | raw: curl -sSL get.docker.com | sh 4 | 5 | - name: 'add ubuntu user to docker group' 6 | raw: sudo usermod -aG docker ubuntu -------------------------------------------------------------------------------- /roles/git/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install/update git package 3 | package: 4 | name: "{{ item }}" 5 | state: latest 6 | with_items: 7 | - git -------------------------------------------------------------------------------- /roles/openfaas/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: 'Bring in OpenFaas' 3 | raw: docker swarm init --advertise-addr eth0 && \ 4 | git clone https://github.com/openfaas/faas && \ 5 | cd faas && \ 6 | git checkout 0.6.7 && \ 7 | ./deploy_stack.sh --------------------------------------------------------------------------------