-
[79일차] Final Project Day_11교육/코드스테이츠 2023. 3. 21. 18:18
Terraform
APIgateway
오류 발생
Terraform을 이용해 APIgateway를 구현 완료 후 테스트 시 에러 발생
원인 파악
- Terraform 리소스 부족
- 권한 미부여
- Lambda zip파일 오류
- Cloudwatch 확인 시 아무 응답도 없다.
- 필요권한을 확인 후 이상 없음을 확인
- 콘솔에서 lambda를 테스트해본 결과 정상적으로 실행되며 파일 오류 없음을 확인
- Terraform 공식문서를 보면 확인해본 결과 리소스에도 오류가 없음을 확인
- 콘솔에서 생성된 Lambda만 테스트 해본 결과가 정삭적으로 실행되는 것은 APIgateway 설정이 문제가 있다는것이라 판단함.
- Terraform으로 생성된 APIgateway를 콘솔에서 확인해본 결과 REST api(v1)으로 동작하고 있었으며, serverless 프레임워크 설정에는 HTTPapi(v2)으로 동작하고 있었다.
문제 해결
- Terraform으로 apigateway를 만들경우 restapi가 기본값으로 생각했었다.
- serverless framwork 공식문서를 찾아본 결과 aws_apigatewayv2_api라는 HTTP 통신을 위한 리소스가 있는걸 확인했다.
- 테라폼 공식 문서 확인 결과 v2라는 HTTP통신을 위한 리소스를 확인
- aws_api_gateway_rest_api리소스를 aws_apigatewayv2_api리소스로 수정 후 정상적으로 실행되었다.
수정 전 rest_api 리소스를 사용한 Terraform 코드
resource "aws_api_gateway_rest_api" "admin_api" { name = "admin_api" } resource "aws_api_gateway_resource" "admin_api_parnet" { rest_api_id = aws_api_gateway_rest_api.admin_api.id parent_id = aws_api_gateway_rest_api.admin_api.root_resource_id path_part = "products" } resource "aws_api_gateway_resource" "admin_api" { rest_api_id = aws_api_gateway_rest_api.admin_api.id parent_id = aws_api_gateway_resource.admin_api_parnet.id path_part = "{id}" } resource "aws_api_gateway_method" "admin_api" { rest_api_id = aws_api_gateway_rest_api.admin_api.id resource_id = aws_api_gateway_resource.admin_api.id http_method = "PUT" authorization = "NONE" }
=================================================================================
참고 자료
https://www.tinystacks.com/blog-post/api-gateway-rest-vs-http-api-what-are-the-differences/
API Gateway REST vs. HTTP API: What Are The Differences?
How do these two versions of the same technology differ? A quick rundown of whether REST or HTTP APIs represent the best investment.
www.tinystacks.com
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html
Choosing between REST APIs and HTTP APIs - Amazon API Gateway
Choosing between REST APIs and HTTP APIs REST APIs and HTTP APIs are both RESTful API products. REST APIs support more features than HTTP APIs, while HTTP APIs are designed with minimal features so that they can be offered at a lower price. Choose REST API
docs.aws.amazon.com
https://hevodata.com/learn/http-api-vs-rest-api/#difference
HTTP API vs REST API: 3 Critical Differentiators - Learn | Hevo
Have you heard about HTTP APIs. Do you know the differences between HTTP API and REST API. If not, read this article, to learn more about HTTP API vs REST API.
hevodata.com
'교육 > 코드스테이츠' 카테고리의 다른 글
[81일차] Final Project 프로젝트 정리 (0) 2023.03.23 [80일차] Final Project Day_12 (0) 2023.03.22 [78일차] Final Project Day_10 (0) 2023.03.20 [77일차] Final Project Day_09 (0) 2023.03.18 [76일차] Final Project Day_07 ~ 08 (0) 2023.03.16