Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sample aws assignment

Reading

Approach

  1. Create the infra manually through the console and get it working as per the tests.
  2. Create the infra through the aws cli (https://aws.amazon.com/cli/) tool and get it working as per the tests.
  3. Create the infra through terraform and get it working as per the tests.

Problem

  1. Create 1 VPC:

    - name: test-vpc-1
    
  2. 1 internet gateway:

    - name: test-vpc-igw-1
    
  3. 2 Subnets associated with above vpc:

    - name: test-public-subnet-1 (associated with the above internet gateway)   
    - name: test-private-subnet-1
    
  4. 2 EC2 instances in the above VPC

    - name: test-instance-1
    - subnet: test-private-subnet-1
    
    - name: test-instance-2
    - subnet: test-private-subnet-1
    
    - name: test-bastion-host
    - subnet: test-public-subnet-1
    
    - requirement: test-bastion-host should be able to ssh into test-instance-1
      and test-instance-2 as they are not exposed to the internet
    
  5. The above 2 instances (test-instance-1 and test-instance-2) should be running a REST API server (django, flask, tomcat, etc. - your choice)

    - description: Create a REST API for adding, viewing, deleting users
    
    - endpoint: /api/v1/health
    - method: POST
    - headers:
      - username: admin
      - password: complex_password_your_choice
    - payload: {"status": "good"} or {"status": "bad"}
    - returns:
      - body: empty
      - http status: 200
    
    - endpoint: /api/v1/health
    - method: GET
    - payload: empty
    - returns:
      - body: {"health": "good"} or {"health": "bad"} depending on the value
        set by the above call
      - http status: 200 or 500 depending on good or bad
    
    - endpoint: /api/v1/user
    - method: POST
    - headers:
      - username: admin
      - password: complex_password_your_choice
    - payload: {"username": "user1"}
    - returns:
      - body: {"status": "added"}
      - http status: 200
    
    - endpoint: /api/v1/user
    - method: GET
    - payload: empty
    - returns:
      - body: {"users": ["user1", "user2"] }
      - http status: 200
    
    - endpoint: /api/v1/user
    - method: DELETE
    - headers:
      - username: admin
      - password: complex_password_your_choice
    - payload: {"username": "user1"}
    - returns:
      - body: empty
      - http status: 200 on success
      - http status: 404 if username is invalid
    
  6. 1 ELB associated with the above 2 instances

    - test-elb
    - The ELB should check the health
      api endpoint:
      - if the instance is healthy - send it the api request (AWS does this on
      your behalf if you setup the health check properly)
      - if the instance is unhealthy - mark it as unhealthy (same condition as above)
    
  7. Testing (let me know if the curl commands are invalid):

    1. Test the health endpoint:

      $ curl -X GET http://your-elb-endpoint/api/v1/health
      
    2. Set health as good and verify:

      $ curl -X POST \
             -d '{"status": "good"}' \
             -H 'Content-Type: application/json' \
             -H 'username: admin' \
             -H 'password: complex_password_your_choice' \
             http://your-elb-endpoint/api/v1/health
      $ curl -X GET http://your-elb-endpoint/api/v1/health
      
    3. Set health as bad and verify:

      $ curl -X POST \
             -d '{"status": "bad"}' \
             -H 'Content-Type: application/json' \
             -H 'username: admin' \
             -H 'password: complex_password_your_choice' \
             http://your-elb-endpoint/api/v1/health
      
      $ curl -X GET http://your-elb-endpoint/api/v1/health
      
    4. Create user1:

      $ curl -X POST \
             -d '{"username": "user1"}' \
             -H 'Content-Type: application/json' \
             -H 'username: admin' \
             -H 'password: complex_password_your_choice' \
             http://your-elb-endpoint/api/v1/user
      
      $ curl -X GET http://your-elb-endpoint/api/v1/user
      
    5. Create user2:

      $ curl -X POST \
             -d '{"username": "user2"}' \
             -H 'Content-Type: application/json' \
             -H 'username: admin' \
             -H 'password: complex_password_your_choice' \
             http://your-elb-endpoint/api/v1/user
      
      $ curl -X GET http://your-elb-endpoint/api/v1/user
      
    6. Delete user1:

      $ curl -X DELETE \
             -d '{"username": "user1"}' \
             -H 'Content-Type: application/json' \
             -H 'username: admin' \
             -H 'password: complex_password_your_choice' \
             http://your-elb-endpoint/api/v1/user
      
      $ curl -X GET http://your-elb-endpoint/api/v1/user
      
    7. Any more interesting test cases you can come up with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.