技術2024-05-29: Lambdaの備忘録

投稿日:
技術
AWS

技術2024-05-29: Lambdaの備忘録

以前Lambdaで作ったAPIを作り直すときに思い出しづらかったところをメモ

環境変数

コード の Tools → Show Environment Variablesから編集できるかと思ったら編集画面ではなかった

Environment Variables

To list your environment variables here for quick reference, use the keyboard shortcut (For macOS, press 'Command-Shift-E' for Windows 'Ctrl-Shift-E') or choose Tools, Show Environment Variables.

Environment variables remain encrypted when listed in the console code editor. If you enabled encryption helpers for encryption in transit, then those settings remain unchanged. For more information, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-encryption.

This file is read-only and is only available on the Lambda console. This file is not included when you download the function's .zip file archive and you can't add environment variables by uploading this file. To add or edit environment variables, choose Configuration, then choose Environment variables.

List of environment variables

No environment variables are configured for the function.

設定 → 環境変数 でフィールドに入力

これで改めて コード に戻って Tools → Show Environment Variables を見ると追加されている

Environment Variables

To list your environment variables here for quick reference, use the keyboard shortcut (For macOS, press 'Command-Shift-E' for Windows 'Ctrl-Shift-E') or choose Tools, Show Environment Variables.

Environment variables remain encrypted when listed in the console code editor. If you enabled encryption helpers for encryption in transit, then those settings remain unchanged. For more information, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-encryption.

This file is read-only and is only available on the Lambda console. This file is not included when you download the function's .zip file archive and you can't add environment variables by uploading this file. To add or edit environment variables, choose Configuration, then choose Environment variables.

List of environment variables

OPENAI_API_KEY = sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

NPMの利用

Node.jsでimport (require) するためにはカスタムレイヤーを作る必要がある。

ローカルの適当な空ディレクトリーでnpm installして、生成されたnode_moduleフォルダーをzipで固めてアップロード

そのうえでカスタムレイヤーを追加

テスト

Testボタンを押すと現在のコードでテストしてくれるのかと思いきや、一旦Deployしないといけない

著者紹介

岩淵夕希物智 butchi_y

言語を作る博士(工学)

ART, Research, Techの人

スポンサーリンク