LoginSignup
1
1

More than 3 years have passed since last update.

DynamodbをLambdaからSQLっぽく操作する

Posted at

説明の前に

pipのモジュールを利用する方法は、下記の記事を参考にさせていただきました。
ありがとうございました。

【Python】AWS Lambdaで外部モジュールを使用する
https://qiita.com/SHASE03/items/16fd31d3698f207b42c9

1.準備

LambdaにPipのモジュールを持ってくる必要があるため、ローカルにDQLモジュールをインストールする。

プロジェクトフォルダ内で、下記

$pip install dql -t ./

2. ソースコード

ファイル名はlambda_function.py

import dql
def lambda_handler(event, context): 
    engine = dql.Engine()
    engine.connect(region="us-west-2")
    results = engine.execute("DELETE FROM tablename WHERE tm >= 1420071600 AND tm <= 1420705200;")
    print(results)
    return "hi world"

regiontablename、クエリなどは任意の設定に修正してください。

3. zip化してアップロード

zip -r dpl.zip ./*

完成したZIPをLambdaにアップロードすれば完成です。

1
1
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
1
1