From 13481266ba80aeefb3073579b438336723c5b448 Mon Sep 17 00:00:00 2001 From: Arnav <48650781+arnavrneo@users.noreply.github.com> Date: Wed, 3 Apr 2024 23:31:27 +0530 Subject: [PATCH 1/2] update/ec2-playbook --- url-shortener/playbook/1_create_ec2.yaml | 86 ++++++++++++++---------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/url-shortener/playbook/1_create_ec2.yaml b/url-shortener/playbook/1_create_ec2.yaml index 50afc47..a72b5ae 100644 --- a/url-shortener/playbook/1_create_ec2.yaml +++ b/url-shortener/playbook/1_create_ec2.yaml @@ -1,68 +1,84 @@ --- -- +- name: Create EC2 instances - hosts: localhost_group - connection: local + hosts: localhost + become: true + connection: local gather_facts: false vars_prompt: - - name: aws_profile + - name: aws_profile prompt: "Enter aws profile: " - private: False + private: false - name: region prompt: "Enter region: " - private: False + private: false default: us-east-1 - + + - name: sec_group + prompt: "Enter security group id: " + private: false + # default: "sg-012wxxxxx" + + - name: sg_desc + prompt: "Desc about Security Group: " + private: false + default: Custom Security Group + - name: image prompt: "Enter ami-id: " - private: False - default: ami-080e1f13689e07408 + private: false + default: ami-080e1f13689e07408 # ubuntu - name: instance_type prompt: "Enter instance type: " - private: False + private: false default: t2.micro - - name: sec_group - prompt: "Enter security group id: " - private: False - #default: "sg-012wxxxxx" - + - name: key_name + prompt: "Enter key name: " + private: false + default: ansible + + - name: count + prompt: "Enter count of instances: " + private: false + default: 1 + + tasks: - - name: Create SG + - name: Create Security Group amazon.aws.ec2_security_group: - name: "{{ sec_group }}" - description: "Test sg" - region: "{{ region }}" - aws_profile: "{{ aws_profile }}" - rules: - - proto: tcp - ports: - - 22 - cidr_ip: 0.0.0.0/0 - rule_desc: allow_ssh + name: "{{ sec_group }}" + description: "{{ sg_desc }}" + region: "{{ region }}" + aws_profile: "{{ aws_profile }}" + rules: + - proto: tcp + ports: + - 22 + cidr_ip: 0.0.0.0/0 + rule_desc: allow_ssh - - proto: tcp - ports: + - proto: tcp + ports: - 3000 - cidr_ip: 0.0.0.0/0 - rule_desc: frontend-exposed - - + cidr_ip: 0.0.0.0/0 + rule_desc: frontend-exposed + - name: Create an instance amazon.aws.ec2_instance: - key_name: ansible + key_name: "{{ key_name }}" aws_profile: "{{ aws_profile }}" instance_type: "{{ instance_type }}" region: "{{ region }}" image_id: "{{ image }}" security_group: "{{ sec_group }}" network: - assign_public_ip: true + assign_public_ip: true wait: true - exact_count: 1 + exact_count: "{{ count }}" tags: Ansible: urlShortenerServer From e72347c58b271a516df593ac27816071d0b6882f Mon Sep 17 00:00:00 2001 From: Arnav <48650781+arnavrneo@users.noreply.github.com> Date: Thu, 11 Apr 2024 21:24:53 +0530 Subject: [PATCH 2/2] README --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..ba6d07c --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# url.ly - a url-shortener service + +This project aims to implement a decoupled & scalable architecture for url shortener service. + +# Architecture + +This project uses: +- `Nextjs` as its frontend; +- `Golang` & `Expressjs` as the backend servers configured with Nginx for load-balancing; +- `MongoDB` as non-relational db for authentication +- `Redis` as in-memory key-value db for url keys management + +- For scalability and portability, both the frontend and backend are containerized using Docker and can be spun-up easily using docker-compose. +- Ansible playbooks and roles are used for automating the service setup & infrastructure creation of single (or multiple) EC2 on AWS. They are used for: + - Creation of a security group (with relevant properties) for EC2 instances + - Creation of EC2 instances & attaching of the defined security group + - Installation of Docker on those instances + - Running of the url-shortener service through user input