Amazon API Gateway๋Š” REST API๋ฅผ ์‰ฝ๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ์„œ๋น„์Šค๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„๋ฅผ ๋ณ„๋„๋กœ ์ž‘์„ฑํ•˜์ง€ ์•Š์•„๋„ Lambda ํ•จ์ˆ˜ ๋˜๋Š” AWS ์„œ๋น„์Šค์™€ ํ†ตํ•ฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๊ณ  ์žˆ๋‹ค. Amazon API Gateway์™€ Amazon SQS ์„œ๋น„์Šค๋ฅผ ์‚ฌ์šฉํ•ด ์™ธ๋ถ€ ์‹œ์Šคํ…œ์œผ๋กœ๋ถ€ํ„ฐ ์ „๋‹ฌ๋˜๋Š” ์ฝœ๋ฐฑ ๊ฒฐ๊ณผ๋ฅผ ์ˆ˜์‹ ํ•˜๊ณ  SQS ๋Œ€๊ธฐ์—ด์— ๋ฉ”์‹œ์ง€๋กœ ์—ฐ๋™ํ•˜๋Š” ๊ตฌ์„ฑ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, Bizppurio API๋ฅผ ํ†ตํ•ด ์นด์นด์˜ค ์•Œ๋ฆผํ†ก ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐœ์†กํ•˜๋Š” ๊ฒฝ์šฐ ๋ฐœ์†ก ๊ฒฐ๊ณผ๋ฅผ ์‚ฌ์ „์— ๋“ฑ๋กํ•œ URL๋กœ ๋น„๋™๊ธฐ๋กœ ์ฝœ๋ฐฑํ•ด์ฃผ๋Š” ๋ฐฉ์‹์„ ์ œ๊ณตํ•ด์ฃผ๊ณ  ์žˆ๋Š”๋ฐ ์ด ๋ฐœ์†ก ๊ฒฐ๊ณผ๋ฅผ ์ˆ˜์‹ ํ•˜์—ฌ ๋น„๋™๊ธฐ ๋Œ€๊ธฐ์—ด๋กœ ๋“ฑ๋กํ•ด๋‘๊ณ  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„์—์„œ ์Šค์ผ€์ค„์— ์˜ํ•ด ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„๊ฐ€ ๋ฐœ์†ก ๊ฒฐ๊ณผ๋ฅผ ๊ทธ๋Œ€๋กœ ๋ฐ›๋Š” ๊ฒฝ์šฐ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„๊ฐ€ ๋ฐฐํฌ๋˜๋Š” ๊ณผ์ •์—์„œ๋Š” ์ผ๋ถ€ ๋ฐœ์†ก ๊ฒฐ๊ณผ๊ฐ€ ์œ ์‹ค๋  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ๋ฅผ ๋‚ด์žฌํ•˜๊ฒŒ ๋œ๋‹ค.

Amazon API Gateway REST API

REST API๋Š” HTTP API์™€ ๋‹ค๋ฅด๊ฒŒ ์š”์ฒญ์— ๋Œ€ํ•œ ๊ฒ€์ฆ ๋˜๋Š” ๋ฆฌ์†Œ์Šค ์ •์ฑ…์— ์˜ํ•œ ํŠธ๋ž˜ํ”ฝ ์ œํ•œ ๋“ฑ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ถ€๋ถ„์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ œ๊ณตํ•˜๊ณ  ์žˆ๋‹ค. ๋˜ํ•œ, ์š”์ฒญ ํŽ˜์ด๋กœ๋“œ๋ฅผ ๋ณ€ํ™˜ํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ SQS ๋ฉ”์‹œ์ง€๋ฅผ ๋“ฑ๋กํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” REST API๋กœ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด AWS ์„œ๋น„์Šค ํ†ตํ•ฉ์œผ๋กœ Simple Queue Service๋ฅผ ์„ ํƒํ•˜๊ณ  ๊ฒฝ๋กœ ์žฌ์ •์˜๋ฅผ ์„ ํƒํ•˜์—ฌ SQS ๋Œ€๊ธฐ์—ด์„ ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค. ์‹คํ–‰ ์—ญํ• ์€ SQS ๋Œ€๊ธฐ์—ด์— ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋„๋ก SQS:SendMessage ๊ถŒํ•œ์ด ํฌํ•จ๋œ IAM Role์˜ ARN์„ ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

Amazon SQS ๋Œ€๊ธฐ์—ด์— ๋Œ€ํ•œ ์•ก์„ธ์Šค ์ •์ฑ…

Amazon API Gateway์— ๋Œ€ํ•œ IAM Role์— AmazonSQSFullAccess ์ •์ฑ…์„ ์—ฐ๊ฒฐํ•ด๋„ ๋˜์ง€๋งŒ ์•„๋ž˜์™€ ๊ฐ™์ด SQS ๋Œ€๊ธฐ์—ด์˜ ์•ก์„ธ์Šค ์ •์ฑ…์— IAM Role์ด ๊ถŒํ•œ์„ ๊ฐ€์ง€๋„๋ก ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ์‹คํ–‰ ์—ญํ• ์— ์ž…๋ ฅํ•œ ARN์ด SQS ๋Œ€๊ธฐ์—ด์— ๋Œ€ํ•œ ๊ถŒํ•œ์„ ๋ณด์œ ํ•˜๊ณ  ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ Access Denied ์‘๋‹ต์„ ๋ฐ›๊ฒŒ ๋œ๋‹ค.

๋ฉ”์„œ๋“œ ์š”์ฒญ ์„ค์ •ํ•˜๊ธฐ (Optional)

REST API๋Š” ๋ฉ”์„œ๋“œ ์š”์ฒญ ์„ค์ •์„ ํ†ตํ•ด ์š”์ฒญ ํ—ค๋”์™€ ๋ณธ๋ฌธ์— ๋Œ€ํ•œ ๊ฒ€์ฆ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. ์š”์ฒญ ๊ฒ€์‚ฌ๊ธฐ์— ์ฟผ๋ฆฌ ๋ฌธ์ž์—ด ํŒŒ๋ผ๋ฏธํ„ฐ ๋ฐ ํ—ค๋” ๊ฒ€์ฆ์„ ์„ ํƒํ•˜๊ณ  ์•„๋ž˜์™€ ๊ฐ™์ด Content-Type ํ—ค๋” ์œ ๋ฌด์™€ ์š”์ฒญ ํŽ˜์ด๋กœ๋“œ์— ๋Œ€ํ•œ ๋ชจ๋ธ ์Šคํ‚ค๋งˆ๋ฅผ ๋งŒ๋“ค์–ด์„œ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. REST API์— ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ ๋ชจ๋ธ์€ JSON ์Šคํ‚ค๋งˆ ๋“œ๋ž˜ํ”„ํŠธ 4๋กœ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ†ตํ•ฉ ์š”์ฒญ ์„ค์ •ํ•˜๊ธฐ

REST API์˜ ํ†ตํ•ฉ ์š”์ฒญ ์„ค์ •์—์„œ๋Š” ์ฝœ๋ฐฑ ๊ฒฐ๊ณผ๋กœ ํฌํ•จ๋˜๋Š” ์š”์ฒญ ํŽ˜์ด๋กœ๋“œ๋ฅผ SQS ๋ฉ”์‹œ์ง€๋กœ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋„๋ก Content-Type: application/x-www-form-urlencoded ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ๋งคํ•‘ ํ…œํ”Œ๋ฆฟ์— SendMessage์™€ MessageBody๋ฅผ ๊ตฌ์„ฑํ•˜์—ฌ SQS ๋ฉ”์‹œ์ง€๋กœ ์ „๋‹ฌ๋˜๋„๋ก ์„ค์ •ํ•ด์•ผํ•œ๋‹ค.

ํ†ตํ•ฉ ์‘๋‹ต ์„ค์ •ํ•˜๊ธฐ (Optional)

ํ†ตํ•ฉ ์‘๋‹ต ์„ค์ •์ด ๋ฐ˜๋“œ์‹œ ํ•„์š”ํ•˜์ง€๋Š” ์•Š์ง€๋งŒ SQS ๋ฉ”์‹œ์ง€ ๋“ฑ๋ก ์‹œ ์ „๋‹ฌ๋˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ์‘๋‹ตํ•˜์ง€ ์•Š๋„๋ก ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋น„์ฆˆ๋ฟŒ๋ฆฌ์˜ค์—์„œ ์•Œ๋ฆผํ†ก ๋ฐœ์†ก ๊ฒฐ๊ณผ๋ฅผ ์ฝœ๋ฐฑ์œผ๋กœ ์ „๋‹ฌํ•ด์ค„๋•Œ ์‘๋‹ต ํŽ˜์ด๋กœ๋“œ๋ฅผ ํ™•์ธํ•˜์ง€ ์•Š์„๊ฒƒ์ด๋ฏ€๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ๋นˆ ์‘๋‹ต์œผ๋กœ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. ๋งŒ์•ฝ, ๋นˆ ์‘๋‹ต์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ํ†ตํ•ฉ ์‘๋‹ต์„ ์„ค์ •ํ•˜๊ธฐ ์ด์ „์— ๋ฉ”์„œ๋“œ ์‘๋‹ต์— 200์— ๋Œ€ํ•œ ์ƒํƒœ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผํ•œ๋‹ค.


ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ… ๐Ÿ”ฅ

Amazon API Gateway์™€ Amazon SQS ์—ฐ๋™ ๊ตฌ์„ฑ ์‹œ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ์˜ค๋ฅ˜์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋„๋ก ํ•˜์ž. REST API๋ฅผ Amazon SQS์™€ ํ†ตํ•ฉํ•˜๊ณ  ์ผ๋ฐ˜์ ์ธ ์˜ค๋ฅ˜๋ฅผ ํ•ด๊ฒฐํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ•˜๋‚˜์š”?์— ์ผ๋ถ€ ์˜ค๋ฅ˜์— ๋Œ€ํ•œ ํ•ด๊ฒฐ ๋ฐฉ์•ˆ์ด ์ •๋ฆฌ๋˜์–ด์žˆ๋‹ค.

UnknownOperationException

Thu Sep 19 09:44:10 UTC 2024 : Received response. Status: 404, Integration latency: 2 ms
Thu Sep 19 09:44:10 UTC 2024 : Endpoint response body before transformations: <UnknownOperationException/>
  • Content-Type ์„ application/x-www-form-urlencoded ๋กœ ์ž…๋ ฅํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ
  • ๋งคํ•‘ ํ…œํ”Œ๋ฆฟ์— Action=SendMessage๋ฅผ ํฌํ•จํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ

AccessDenied

{"Error":{"Code":"AccessDenied","Message":"Access to the resource https://sqs.ap-northeast-2.amazonaws.com/xxxxxxxx/kakao-at-result is denied.","Type":"Sender"},"RequestId":"aba6b507-a4c5-512c-a55f-ea625778d5ff"}
  • ์‹คํ–‰ ์—ญํ• ์˜ IAM Role์ด SQS ๋Œ€๊ธฐ์—ด์— ๋Œ€ํ•œ ๊ถŒํ•œ์ด ์—†๋Š” ๊ฒฝ์šฐ
  • ์š”์ฒญ ๋ณธ๋ฌธ์— ํŠน์ˆ˜ ๋ฌธ์ž๊ฐ€ ํฌํ•จ๋˜์–ด์žˆ๋Š”๋ฐ $util.urlEncode ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ

Nginx ์—์„œ API Gateway ๋กœ ํŠธ๋ž˜ํ”ฝ ๋ฏธ๋Ÿฌ ์‹œ ์˜ค๋ฅ˜

no resolver defined to resolve xxxxxx.execute-api.ap-northeast-2.amazonaws.com
xxxxxx.execute-api.ap-northeast-2.amazonaws.com could not be resolved (110: Operation timed out) while sending to client

Amazon API Gateway ์—์„œ ์‚ฌ์šฉ์ž ์ •์˜ ๋„๋ฉ”์ธ์„ ๊ตฌ์„ฑํ•˜๊ธฐ ์ด์ „์— ๊ธฐ์กด์— ์ฝœ๋ฐฑ ๊ฒฐ๊ณผ๋ฅผ ์ˆ˜์‹ ํ•˜๋˜ ๊ฒƒ์„ API Gateway์˜ ์Šคํ…Œ์ด์ง€ URL์„ ํ†ตํ•ด ๋ฐœ์†ก ๊ฒฐ๊ณผ๋ฅผ ์ „๋‹ฌ๋˜๋„๋ก ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์œ„ํ•ด์„œ Nginx์˜ ํŠธ๋ž˜ํ”ฝ ๋ฏธ๋Ÿฌ๋ง์„ ๊ตฌ์„ฑํ•˜๊ณ ์ž ํ–ˆ์„๋•Œ ๋„๋ฉ”์ธ์„ ์ฐพ์„ ์ˆ˜ ์—†๋Š” ์˜ค๋ฅ˜๋ฅผ ๊ฒฝํ—˜ํ–ˆ๋‹ค. ์ด์— ๋Œ€ํ•ด์„œ ์ฐพ์•„๋ณด๋‹ˆ ๋‚ด๋ถ€ DNS ๊ฐ€ ์•„๋‹Œ ํด๋ผ์šฐ๋“œํ”Œ๋ ˆ์–ด ๋˜๋Š” ๊ตฌ๊ธ€ DNS๋กœ ์ง€์ •ํ•˜๋ฉด ํ•ด๊ฒฐ ๊ฐ€๋Šฅํ•˜๋‹ค.

location = /mirror_api_gw {
  internal;
  resolver 1.1.1.1 8.8.8.8 valid=10s;
  proxy_pass https://xxxxxx.execute-api.ap-northeast-2.amazonaws.com/dev$request_uri;
}