[PYTHON] Operate Dynamodb from Lambda like SQL

Before the explanation

For how to use the pip module, I referred to the following article. Thank you very much.

[Python] Using an external module with AWS Lambda https://qiita.com/SHASE03/items/16fd31d3698f207b42c9

1. Preparation

You need to bring the Pip module to Lambda, so install the DQL module locally.

In the project folder,

$pip install dql -t ./

2. Source code

The file name is 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"

Modify region, tablename, query, etc. to any settings.

3. Zip and upload

zip -r dpl.zip ./*

Upload the completed ZIP to Lambda and you're done.

Recommended Posts

Operate Dynamodb from Lambda like SQL
Operate DynamoDB from Python like SQL.
sql from python
LoL ~ Lambda operate Lambda ~
Operate neutron from Python!
Operate LXC from Python
Try automating Qiita's like monitoring with Lambda + DynamoDB + CloudWatch
Tweet from AWS Lambda
Run BigQuery from Lambda
Operate TwitterBot with Lambda, Python