Lambda+APIGateway: CldCvr Hands-On Exercise
BEFORE YOU START (IMPORTANT)
Please read all the following instructions carefully and adhere to them as closely as possible.
Clarify any questions or doubts with the interviewer before you start.
This is an open-web interview, so feel free to use any Internet resources you need.
Setup
Part 1
Using the provided AWS API keys for the given AWS account, write a program that returns a JSON object with the:
instance-id
instance-type
instance-state
region
of every EC2 instance in the given AWS account, across all AWS regions.
You can choose to write your program in any of the languages officially supported by AWS Lambda:
Python
nodeJS
Java
C#
You may use an official AWS SDK such as the boto3 Python library in your program.
The desired output should be JSON similar to:
[
.
.
.
{
"instance-id": "i-072cXXXXXXXXXXXXXX",
"instance-type": "m4.large",
"region": "ap-south-1",
"state": "stopped"
},
{
"instance-id": "i-0573XXXXXXXXXXXXXX",
"instance-type": "t2.micro",
"region": "us-west-2",
"state": "started"
}
.
.
.
]
NOTE: Submit your solution to the interviewer after you complete Part1. Don't proceed to Part2 without the interviewer's approval.
bonus points!
Instead of sequentially checking the instances in every AWS region (which can easily take upwards of 20 seconds), parallelize your solution!
Evaluate every AWS region in parallel, then combine the individual results into a single final list.
Part 2
Deploy and run the program you wrote in Part1 as an AWS Lambda Function.
Use AWS API Gateway to expose your function as a REST service.
Use the official AWS Lambda + API Gateway Getting Started Guide for help if you are new to AWS Lambda.
Share the API Gateway URL (for example: https://381dXXXXXXX.execute-api.us-west-2.amazonaws.com/ListAllInstances) with the interviewer.
A simple GET request on the APIGateway URL (for example pasting the URL into a browser) should yield the same output JSON from Part1:
[
.
.
.
{
"instance-id": "i-072cXXXXXXXXXXXXXX",
"instance-type": "m4.large",
"region": "ap-south-1",
"state": "stopped"
},
{
"instance-id": "i-0b73XXXXXXXXXXXXXX",
"instance-type": "t2.micro",
"region": "us-west-2",
"state": "started"
}
.
.
.
]
Important!
Create your Lambda Function and API Gateway in the Mumbai AWS region (ap-south-1) only.
Your API Gateway should be configured to run in Proxy Mode (which is the default option).
Your Lambda function will have to return output in a suitable format for Proxy Mode.
bonus points!
Use a FAAS (Function As A Service) framework such as serverless or apex to deploy and execute your Lambda function.