Best Practice
- RESTful API는 2가지 타입이 존재합니다.
- 특별한 기능을 요구하지 않는다면 HTTP API를 사용하세요.
- API는 팀, 마이크로 서비스, Custom Domain Name 단위로 생성하세요.
- AWS Management Console은 연습을 위해서 익히기 위해서 쓰세요.
- Infrastructure as Code(IaC) 기반으로 작성하세요. (SAM, CloudFormation, Cloud Development Kit, Terraform 등)
- RPS(requests per second) 기준 스로틀링 제한이 있습니다.
- RPS는 계정의 Region 당 10,000개이며 테스트 결과에 따라 Limit 증가 요청 가능합니다.
- 내부적으로 토큰 버킷 알고리즘에 의거 요청에 대한 처리는 최대 5,000개까지만 가능합니다.
- Integration Timeout 설정은 50ms ~ 29s 로 설정이 가능
- Timeout이 길어지면 RPS 제한을 증가해도 요청 처리에 문제가 발생 가능
- Lambda 를 연결했을 경우 Lambda 의 타임아웃을 짧게 구성했다고 하더라도 API GW 레벨에서도 타임아웃을 적절히 짧게 설정해줘야 합니다.
- API GW 에 연결된 백엔드 문제가 API GW 까지 영향을 미치지 않게 하기 위함 입니다.
- API caching 설정해주는게 성능면에서 유리합니다.
- TTL 은 0~3600s 로 설정 가능하며, Default는 300s 입니다.
- CW 지표에는 4XX, 5XX 에러 카운트 정도만 표시되기 때문에 별도 설정을 통해 CW Logs 에 API 로깅을 해주는게 개발할 때 더 편리합니다.
Data Transformation 요건이 없다면 integration type 을 proxy integration 로 연동하면 API Gateway에서 Backend 로 부터 받은 내용을 그대로 리턴합니다.
- Data Transformation 요건이 있다면 , Mapping Template 을 사용
Mapping Template의 Content-Type을 application/json 과 text/html 로 두개를 만들어 놓고 분기 처리 합니다.
(Request Mapping Template에 2개, Response Mapping Template에 2개)- response 시 에는 accept header 값을 보고 어떤 VTL 을 적용할지 선택 가능
- API 문서 관리를 위하여 Swagger / OpenAPI 3 를 활용합니다. Import / Export 지원합니다.
Reference
- https://aws.amazon.com/ko/api-gateway/faqs/
- https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
- https://github.com/hatsari/article/tree/master/aws/aws_api_gw_httpapi
- https://www.cloudconformity.com/knowledge-base/aws/APIGateway/
- Security Overview of AWS API Gateway
- Choosing between HTTP and REST APIs
- Serverless Lens
- https://serverlessland.com/
Blog
- Visualizing Amazon API Gateway usage plans using Amazon QuickSight
- Using multiple segments in Amazon API Gateway base path mapping
- Performing canary deployments for service integrations with Amazon API Gateway
- Integrating Amazon API Gateway private endpoints with on-premises networks
- Building private cross-account APIs using Amazon API Gateway and AWS PrivateLink
- Building a serverless multi-player game that scales
- Introducing Amazon API Gateway service integration for AWS Step Functions
- The serverless LAMP stack part 6: From MVC to serverless microservices
- Building a serverless document scanner using Amazon Textract and AWS Amplify