swagger 파일을 기반으로 테라폼이 적용된 api 게이트웨이 배포
나는 나의 api를 설명하기 위해 swagger 파일을 사용하여 terraform으로 api 게이트웨이를 배치하고 싶다. 으르렁거리는 사람은 이렇게 생겼어요:
swagger: '2.0'
info:
version: '1.0'
title: "CodingTips"
schemes:
- https
paths:
"/api":
get:
description: "Get coding tips"
produces:
- application/json
x-amazon-apigateway-integration: ${apiIntegration}
responses:
'200':
description: "Codingtips were successfully requested"
테라폼이 그런 말을 해주고 있어요.
이 때문에 나는 이 api의 방법과 통합을 기다리지 않고 REST api를 전개하려고 생각하고 있다.
이것은 나로 하여금 에 추가해야 하는 방향으로 생각하게 만들었다. 하지만 스웨거를 사용하여 방법과 통합 자원을 정의하지 않기 때문에 무엇에 의존해야 할지 모르겠다. 그들은 자동적으로 스웨거 정의에서 차감되어야 한다.
제가 생각하는 방향이 맞는 건가요, 그렇다면 무엇을 의지해야 하나요? 아니면 내가 이 api를 배포하려는 방식에 다른 문제가 있는 것인가요.
내 파일은 다음과 같습니다:
resource "aws_api_gateway_rest_api" "codingtips-api-gateway" {
name = "ServerlessExample"
description = "Terraform Serverless Application Example"
body = "${data.template_file.codingtips_api_swagger.rendered}"
}
locals{
"get_codingtips_arn" = "${aws_lambda_function.get-tips-lambda.invoke_arn}"
"x-amazon-coding-tips-apigateway-integration" = <<EOF
#
uri = "${local.get_codingtips_arn}"
passthroughBehavior: when_no_match
httpMethod: POST
type: aws_proxy
credentials: "${aws_iam_role.api_gateway_role.arn}"
EOF
}
data "template_file" codingtips_api_swagger{
template = "${file("./swagger.yaml")}"
vars {
apiIntegration = "${indent(8, local.x-amazon-coding-tips-apigateway-integration)}"
}
}
resource "aws_api_gateway_deployment" "codingtips-api-gateway-deployment" {
rest_api_id = "${aws_api_gateway_rest_api.codingtips-api-gateway.id}"
stage_name = "test"
}
어떻게 고칠 수 있을까요?
뭐가 잘못됐는지 알아냈어요. 그것은 블록의 구문상의 오류입니다. 등호 대신 콜론을 사용하는 게 좋을 거예요. 그러면 블록은 다음과 같이 나타납니다:
locals{
"get_codingtips_arn" = "${aws_lambda_function.get-tips-lambda.invoke_arn}"
"x-amazon-codingtips-get-apigateway-integration" = <<EOF
# comment for new line
uri: "${aws_lambda_function.get-tips-lambda.invoke_arn}"
passthroughBehavior: when_no_match
httpMethod: POST
type: aws_proxy
EOF
}
이를 조사해보니 swagger.yaml에 다음과 같이 지정하면 더 쉽게 읽히는 것을 알 수 있었습니다:
swagger: '2.0'
info:
version: '1.0'
title: "CodingTips"
schemes:
- https
paths:
"/api":
get:
description: "Get coding tips"
produces:
- application/json
responses:
'200':
description: "The codingtips request was successful."
x-amazon-apigateway-integration:
uri: ${uri_arn}
passthroughBehavior: "when_no_match"
httpMethod: "POST"
type: "aws_proxy"
테라폼의 및 블록은 다음과 같습니다:
data "template_file" codingtips_api_swagger{
template = "${file("swagger.yaml")}"
vars {
uri_arn = "${local.get_codingtips_arn}"
}
}
locals {
"get_codingtips_arn" = "${aws_lambda_function.get-tips-lambda.invoke_arn}"
}
경로가 여러 개인 경우 x-uri-apigateway-integration: uri: ${uri_arn} passthroughBehavior: "whn_no_match" httpMethod: "POST" 유형: "aws_pass"를 추가해야 합니다
한 번 더 추가하는 것만으로 충분한가요?
또한 나는 당신의 단계를 따랐지만 여전히 보인다: API Gateway Deployment: BadRequest 만들기예외: 메서드에 대해 정의된 통합이 없습니다
람다가 이걸 작동시키길 원한다.
'resource "aws_premission" "premission" {
statement_id = "허용"양돈길호출"
action = "실행:함수 호출"
function_name = aws_function.function_function.function.function_name
주체 = var.lf_trigger_event_source_type
source_arn = "${aws_api_rest_api.sources_rest_api.sources_rest_api."실행_arn}//"
depend_dependation = [ aws_api_depploy.dependation_dependation]'에 의존합니다
'개발하자' 카테고리의 다른 글
Svelte 구성 요소를 트리거/강제 업데이트하는 방법 (0) | 2023.09.11 |
---|---|
젠킨스를 사용하여 kubernetes 배포 업데이트 (0) | 2023.09.09 |
pyinstaller로 생성된 python 실행 파일 자동 업데이트 (0) | 2023.09.08 |
비주얼 스튜디오 코드에서 스크립트 파일을 디버그하는 방법 (0) | 2023.09.08 |
svelte에서 내보낼 빌드 js 및 css 파일 이름을 지정하는 방법 (0) | 2023.09.07 |