Skip to content

Commit

Permalink
AWS API Gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
sunilsoni committed Oct 3, 2023
1 parent 1906bd1 commit 8efac35
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 50 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 53 additions & 49 deletions docs/aws/api-gateway.md
Original file line number Diff line number Diff line change
@@ -1,92 +1,96 @@
---
layout: default
title: API Gateway
title: AWS API Gateway
parent: AWS
resource: true
desc: " AWS API Gateway interview questions and answers."
desc: "A comprehensive guide to AWS API Gateway, including interview questions and answers."
categories: [API Gateway]

---

# AWS API Gateway
# AWS API Gateway: Your Gateway to Scalable and Secure APIs
{: .no_toc }

<details open markdown="block">
<summary>
Table of contents
Table of Contents
</summary>
{: .text-delta }
1. TOC
1. [Introduction](#introduction)
2. [Key Features](#key-features)
3. [Use Cases](#use-cases)
4. [Configuration Steps](#configuration-steps)
5. [Security Measures](#security-measures)
6. [Deployment and Testing](#deployment-and-testing)
7. [Conclusion](#conclusion)
{:toc}
</details>

---

## Introduction

Amazon Web Services (AWS) API Gateway is a powerful and fully managed service designed to simplify the process of creating, publishing, managing, monitoring, and securing APIs at any scale. It serves as a vital component in the AWS ecosystem, providing developers with a straightforward way to connect their applications to backend services, data, and business logic.

### Key Features

AWS API Gateway comes packed with an impressive array of features, making it a versatile tool for developers:

- **Traffic Management:** It handles the heavy lifting of accepting and processing hundreds of thousands of concurrent API calls. This includes load balancing, throttling, and request routing to backend services.

- **Cost-Efficient:** AWS API Gateway is cost-effective as it operates on a pay-as-you-go model. You only pay for the API calls you receive and the data transferred out.

- **Versatile Functionality:** It can expose HTTP(S) endpoints for RESTful APIs and effortlessly connect to AWS Lambda functions and DynamoDB databases, providing serverless functionality.

- **Scalability:** With the ability to scale rapidly and effortlessly, API Gateway ensures that your APIs can handle any level of demand, whether it's a startup or an enterprise-level application.

- **Throttling and Security:** API Gateway offers built-in throttling mechanisms to prevent abuse and attacks. You can also secure your APIs using API keys, OAuth 2.0, and JWTs.

## API Gateway
- **Monitoring and Observability:** It seamlessly integrates with AWS CloudWatch for monitoring and observability, allowing you to track and control usage effectively.

### Use Cases

API Gateway is a fully managed service for developers that makes it easy to build, publish, manage, and secure entire APIs. With a few clicks in the AWS Management Console, you can create an API that acts as a “front door” for applications to access data, business logic, or functionality from your back-end services, such as workloads running on EC2) code running on AWS Lambda, or any web application.
AWS API Gateway finds application in a variety of scenarios:

### API Gateway Key Details
- Amazon API Gateway handles all the tasks involved in accepting and processing up to hundreds of thousands of concurrent API calls, including traffic management, authorization and access control, monitoring, and API version management.
- Amazon API Gateway has no minimum fees or startup costs. You pay only for the API calls you receive and the amount of data transferred out.
- API Gateway does the following for your APIs:
- Exposes HTTP(S) endpoints for RESTful functionality
- Uses serverless functionality to connect to Lambda & DynamoDB
- Can send each API endpoint to a different target
- Runs cheaply and efficiently
- Scales readily and effortlessly
- Can throttle requests to prevent attacks
- Track and control usage via an API key
- Can be version controlled
- Can be connected to CloudWatch for monitoring and observability
- Since API Gateway can function with AWS Lambda, you can run your APIs and code without needing to maintain servers.
- Amazon API Gateway provides throttling at multiple levels including global and by a service call.
- In software, a throttling process, or a throttling controller as it is sometimes called, is a process responsible for regulating the rate at which application processing is conducted, either statically or dynamically.
- Throttling limits can be set for standard rates and bursts. For example, API owners can set a rate limit of 1,000 requests per second for a specific method in their REST APIs, and also configure Amazon API Gateway to handle a burst of 2,000 requests per second for a few seconds.
- Amazon API Gateway tracks the number of requests per second. Any requests over the limit will receive a 429 HTTP response. The client SDKs generated by Amazon API Gateway retry calls automatically when met with this response.
- You can add caching to API calls by provisioning an Amazon API Gateway cache and specifying its size in gigabytes. The cache is provisioned for a specific stage of your APIs. This improves performance and reduces the traffic sent to your back end. Cache settings allow you to control the way the cache key is built and the time-to-live (TTL) of the data stored for each method. Amazon API Gateway also exposes management APIs that help you invalidate the cache for each stage.
- You can enable API caching for improving latency and reducing I/O for your endpoint.
- When caching for a particular API stage (version controlled version), you cache responses for a particular TTL in seconds.
- API Gateway supports AWS Certificate Manager and can make use of free TLS/SSL certificates.
- With API Gateway, there are two kinds of API calls:
- Calls to the API Gateway API to create, modify, delete, or deploy REST APIs. These are logged in CloudTrail.
- API calls set up by the developers to deliver their custom functionality: These are not logged in CloudTrail.
- **Backend for Frontend (BFF):** It acts as a "front door" for mobile and web applications, allowing them to access data, services, or business logic from different backend services. This simplifies the client-side application and optimizes performance.

### API Gateway
- **Serverless Architectures:** API Gateway pairs perfectly with AWS Lambda, enabling you to build serverless APIs without the need for server maintenance.

Amazon Web Services (AWS) API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale.
- **Microservices:** It serves as a central hub for managing and routing requests to various microservices, making it easier to maintain and scale complex architectures.

API Gateway enables developers to build RESTful APIs, WebSocket APIs, and HTTP APIs that act as a “front door” for applications to access data, business logic, or functionality from backend services. Developers can use API Gateway to create APIs that integrate with AWS Lambda, AWS Elastic Beanstalk, Amazon EC2, or any publicly accessible web service.
- **Third-Party Integrations:** You can use API Gateway to connect your APIs to third-party services and expose them securely.

API Gateway provides a number of features that make it easy to manage APIs. These features include:
## Configuration Steps

`API creation and management`: Developers can use the API Gateway console or API to create and manage APIs, define resources and methods, and set up authentication and authorization.
To harness the power of AWS API Gateway, follow these steps:

`Integration with AWS services`: API Gateway can be integrated with AWS services such as Lambda, Elastic Beanstalk, and EC2 to create a scalable and reliable backend for APIs.
1. **Create a Lambda Function:** Start by creating a Lambda function that will act as the backend for your API. This function can perform data retrieval, execute business logic, or interact with databases.

`Security and access control`: API Gateway provides a number of features for securing APIs, including support for OAuth 2.0 and JSON Web Tokens (JWTs), and integration with AWS Identity and Access Management (IAM).
2. **Set Up an API Gateway:** Create an API Gateway using the AWS Management Console or the AWS CLI. Define your REST API, configure resources and methods, and set up the endpoints that your clients will access.

`Monitoring and logging`: API Gateway provides detailed metrics and logging for APIs, allowing developers to monitor API usage, identify issues, and troubleshoot problems.
3. **Integrate with Lambda:** Establish integration between your API Gateway and the Lambda function. You can do this through the console or CLI, ensuring that incoming requests are directed to the Lambda function, which then responds to clients.

`API deployment and scaling`: API Gateway makes it easy to deploy APIs to multiple stages (e.g., development, testing, production), and provides automatic scaling to handle changes in API traffic.
4. **Enhance Security:** Secure your API by implementing OAuth 2.0, JWTs, or integrate it with AWS Identity and Access Management (IAM) for granular access control.

5. **Deployment:** Deploy your API to multiple stages (e.g., development, testing, production) using the AWS Management Console or CLI.

### Configure API using AWS API Gateway with AWS Lambda as a backend
6. **Testing:** Rigorously test your API to ensure it functions correctly. Tools like Postman or direct client application requests can help validate your API's performance.

- Create a Lambda function: First, create a Lambda function that will act as the backend for your API. You can do this using the AWS Management Console or the AWS CLI. For example, you could create a function that retrieves data from a database or performs some other business logic.
## Security Measures

- Create an API Gateway: Next, create an API Gateway using the AWS Management Console or the AWS CLI. You'll need to define a REST API and configure its resources and methods. For example, you could define a GET method on the "/users" resource that retrieves a list of users from your Lambda function.
Ensuring the security of your AWS API Gateway is paramount:

- Set up integration between API Gateway and Lambda: Once you've created your API Gateway, you need to set up integration between API Gateway and your Lambda function. You can do this using the AWS Management Console or the AWS CLI. For example, you could set up a Lambda Proxy integration that maps incoming requests to your Lambda function and returns the function's output to the client.
- **OAuth 2.0 and JWT Support:** Implement OAuth 2.0 authorization flows and validate JSON Web Tokens (JWTs) to control access to your API.

- Add security to your API: To secure your API, you can use API Gateway's built-in support for OAuth 2.0 and JSON Web Tokens (JWTs), or you can integrate with AWS Identity and Access Management (IAM) to control access to your API.
- **AWS IAM Integration:** Integrate with AWS Identity and Access Management (IAM) for fine-grained access control, managing permissions at the user and resource level.

- Deploy your API: Once you've configured your API, you can deploy it to a specific stage (e.g., development, testing, production). You can do this using the AWS Management Console or the AWS CLI.
- **API Key Management:** Employ API keys to track and control usage, and optionally limit access to specific clients or applications.

- Test your API: Finally, test your API to make sure it's working as expected. You can do this using a tool like Postman or by sending requests directly from your client application.
## Deployment and Testing

After configuring your API, deploy it to the appropriate stages, monitor its performance, and conduct thorough testing to ensure it meets your requirements. Leverage AWS CloudWatch for real-time monitoring and debugging.

## Conclusion

Amazon API Gateway is a versatile and indispensable tool in the AWS ecosystem, enabling developers to create, secure, and manage APIs with ease. Its robust features and seamless integration with other AWS services make it a go-to choice for API management, from small startups to large enterprises. Whether you're building serverless applications, microservices, or simply need a secure gateway for your frontend applications, AWS API Gateway is your gateway to success.

Explore its capabilities, experiment with different use cases, and discover how it can simplify your API management tasks while enhancing the scalability and security of your applications.

0 comments on commit 8efac35

Please sign in to comment.