プロジェクトの初期化

mkdir my-function
cd my-function
pnpm init

依存関係のインストール

pnpm add -D @types/aws-lambda
pnpm add -D tsdown
pnpm add -D -E @biomejs/biome

コード

src/index.ts:

import { Handler } from "aws-lambda";
 
export const handler: Handler = async (event) => {
	console.log(`Event: ${JSON.stringify(event, null, 2)}`);
 
	return {
		statusCode: 200,
		body: JSON.stringify({
			message: "hello, world",
			nodeVersion: process.version,
		}),
	};
};
 

ビルド

npx tsdown

デプロイ

npx tsdown && cd dist && rm -f my-function.zip && zip my-function.zip index.mjs