14
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LambdaのコードエディタにD&Dでファイルアップロードできるって知ってた?

Posted at

昨年後半に、AWS LambdaのコードエディタがVSCode風になりましたよね。

コードが書きやすくなっただけでなく、この部分にファイルをアップロードできるって知ってました?

image.png

ドラッグアンドドロップでもコマンド(Ctrl + CCtrl + V)でも可能ですが、ディレクトリーをアップロードする場合は、コマンド方式ではエラーになりました。

なので、ちょっとしたライブラリーなら、いちいちLambdaレイヤーを作らなくても追加が可能です。

例えば、PythonのRequestsライブラリーであれば、pip install -t python requestsで取得した後、pythonディレクトリー内のファイル一式を貼り付けるだけです。

image.png

アップロードはちょっと遅いかな?という体感です。

アップロードが終わるとこんな感じになります。

image.png

これだけで、Requestsライブラリーが使用可能です。

コードを書き換えて、

import json
import requests

def lambda_handler(event, context):
    # TODO implement
    response = requests.get("http://www.google.com")
    return {
        'statusCode': 200,
        'body': json.dumps(response.text[:100])
    }

デプロイの後、テスト実行します。

image.png

うまくいきました。

14
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?