๐Ÿš€ TypeScript๋ฅผ ์‚ฌ์šฉํ•˜๋Š” AWS Lambda์˜ ์ตœ์ƒ์œ„ ๋Œ€๊ธฐ

5068 ๋‹จ์–ด awstypescriptcloudserverless
๊ฑฐ์˜ 2๋…„ ์ „์ธ version 14.8.0 release ์— Node.js๋Š” module: unflag Top-Level Await ์ด๋ผ๋Š” ๋ฌธ์ œ #34558์„ ๋งˆ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ฒ„์ „ 14.8๋ถ€ํ„ฐ ES ๋ชจ๋“ˆ ๋‚ด๋ถ€์—์„œ await outside an async function์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฑฐ์˜ 2๋…„์ด ์ง€๋‚œ ํ›„์— Node.js ์ฝ”๋“œ๊ฐ€ ์ด์ ์„ ํ™œ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ๋ฐœ๊ฒฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ esbuild ๋˜๋Š” TypeScript์™€ ๊ฐ™์€ ๋ฒˆ๋“ค๋Ÿฌ ๋ฐ ์ปดํŒŒ์ผ๋Ÿฌ์˜ ์‚ฌ์šฉ์„ ๊ณ ๋ คํ•  ๋•Œ ๊ตฌ์„ฑ์˜ ๋ณต์žก์„ฑ์ด ์ฆ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

์‹คํ–‰ ์„ฑ๋Šฅ



AWS Lambda์™€ ๊ฐ™์€ ์ž„์‹œ ํ™˜๊ฒฝ์—์„œ ์šฐ๋ฆฌ๊ฐ€ ๋‹จ์ถ•ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ€๋ฆฌ์ดˆ๋Š” ์™„๋ฒฝํ•œ ์Šน๋ฆฌ์ž…๋‹ˆ๋‹ค. Earlier this year AWS Lambda ๋Ÿฐํƒ€์ž„์€ Node.js 14+ ๊ธฐ๋Šฅ์— ๋Œ€ํ•œ ์ „์ฒด ์ง€์›์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

(Principal Specialist Solutions Architect Serverless)๊ฐ€ his article์—์„œ ์„ค๋ช…ํ–ˆ๋“ฏ์ด ์•ฝ 45%์˜ ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.



TypeScript๋ฅผ ES ๋ชจ๋“ˆ๋กœ ๋ณ€ํ™˜



AWS Lambda Serverless ๊ฐœ๋ฐœ ๋„๊ตฌ์˜ ์กฐํ•ฉ์œผ๋กœ ์ด๋Ÿฌํ•œ ๊ฐœ์„  ์‚ฌํ•ญ์„ ์‰ฝ๊ฒŒ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‚ด ์˜ˆ๋Š” ๋‹ค์Œ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • Serverless Framework
  • esbuild via serverless-esbuild
  • AWS Lambda ์ฝ”๋“œ ์ž‘์„ฑ์„ ์œ„ํ•œ TypeScript

  • ๋น„๋ฐ€ ์†Œ์Šค๋Š” ๋‹ค์Œ esbuild ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ํ™•์žฅ์ž๊ฐ€ .mjs์ธ Node.js ES ๋ชจ๋“ˆ ํŒŒ์ผ์„ ์ถœ๋ ฅํ•˜๋„๋ก esbuild๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

    format: "esm"
    outputFileExtension: ".mjs"
    platform: "node"
    target: "esnext"
    

    ์ด๋ฅผ ํ†ตํ•ด TypeScript์— ์™„์ „ํ•œ ์œ ํ˜•์˜ AWS Lambda ์ฝ”๋“œ๋ฅผ ๋ณด์œ ํ•˜๊ณ  ํ•ธ๋“ค๋Ÿฌ ๊ธฐ๋Šฅ ์™ธ๋ถ€์—์„œ ์‹คํ–‰await์„ ํ™œ์šฉํ•˜์—ฌ ์„œ๋น„์Šค ์†Œ๋น„์ž์˜ ์‘๋‹ต ์‹œ๊ฐ„์„ ๊ฐœ์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ๋‚ด GitHub์—์„œ ์ „์ฒด ๋ฐ๋ชจ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


    ์—๋‘์•„๋ฅด๋„ ๋ผ๋ฒจ๋กœ / top-level-await-in-aws-lambda-with-typescript


    ๐Ÿš€ TypeScript, esbuild ๋ฐ Serverless Framework์™€ ํ•จ๊ป˜ AWS Lambda์—์„œ ์ตœ์ƒ์œ„ await ์‚ฌ์šฉ





    ๐Ÿš€ TypeScript๋ฅผ ์‚ฌ์šฉํ•˜๋Š” AWS Lambda์˜ ์ตœ์ƒ์œ„ await


    ์ด ์ €์žฅ์†Œ๋Š” TypeScript์—์„œ ์ฝ”๋“œ๋ฅผ ๊ฐœ๋ฐœํ•˜๋Š” ๋™์•ˆ ์‹œ์—ฐํ•ฉ๋‹ˆ๋‹คNode.js ES modules and top-level await in AWS Lambda.

    ์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•ฉ๋‹ˆ๊นŒ?


    serverless-esbuild์„ ์‚ฌ์šฉํ•˜์—ฌ TypeScript ์ฝ”๋“œ๋ฅผ JavaScript๋กœ ํŠธ๋žœ์ŠคํŒŒ์ผํ•ฉ๋‹ˆ๋‹ค.
    ๋น„๋ฐ€ ์†Œ์Šค๋Š” ๋‹ค์Œ esbuild ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ํ™•์žฅ์ž๊ฐ€ .mjs์ธ Node.js ES ๋ชจ๋“ˆ ํŒŒ์ผ์„ ์ถœ๋ ฅํ•˜๋„๋ก esbuild๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
    format: "esm"
    outputFileExtension: ".mjs"
    platform: "node"
    target: "esnext"

    ์ด๋ฅผ ํ†ตํ•ด TypeScript์— ์™„์ „ํ•œ ์œ ํ˜•์˜ AWS Lambda ์ฝ”๋“œ๋ฅผ ๋ณด์œ ํ•˜๊ณ  ํ•ธ๋“ค๋Ÿฌ ๊ธฐ๋Šฅ ์™ธ๋ถ€์—์„œ ์‹คํ–‰await์„ ํ™œ์šฉํ•˜์—ฌ ์„œ๋น„์Šค ์†Œ๋น„์ž์˜ ์‘๋‹ต ์‹œ๊ฐ„์„ ๊ฐœ์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    (Principal Specialist Solutions Architect Serverless)๊ฐ€ his article์—์„œ ์„ค๋ช…ํ–ˆ๋“ฏ์ด ์•ฝ 45%์˜ ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    https://aws.amazon.com/blogs/compute/using-node-js-es-modules-and-top-level-await-in-aws-lambda/


    View on GitHub


  • ํŠธ์œ„ํ„ฐ:
  • ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ