Creating numbering process using python in DynamoDB Local Numbering process

Overview

When using DynamoDB when creating python numbering process If you want to use actual DynamoDB during development ... I think that you will develop using DynamoDB Local, so I will summarize the method. Continuing from Last time, we will actually create a python program.

Advance preparation

Implementation

import os
import boto3

endpoint_url = os.getenv('DYNAMODB_ENDPOINT', 'http://192.168.99.100:8000/')
aws_access_key_id = os.getenv('DYNAMODB_ACCESS_KEY_ID', 'DummyID')
aws_secret_access_key_id = os.getenv('DYNAMODB_SECRET_ACCESS_KEY_ID', 'DummyKey')
aws_region_name = os.getenv('DYNAMODB_REGION', 'ap-northeast-1')

dynamodb = boto3.resource(
    'dynamodb',
    region_name=aws_region_name,
    endpoint_url=endpoint_url,
    aws_access_key_id=aws_access_key_id,
    aws_secret_access_key=aws_secret_access_key_id
)

sequences = dynamodb.Table('sequences')

res = sequences.update_item(
    Key= {
        'sequence_key': 'TEST_SEQ'
        },
    UpdateExpression="ADD #name :increment",
    ExpressionAttributeNames={
        '#name':'val'
        },
    ExpressionAttributeValues={
        ":increment": int(1)
        },
    ReturnValues="UPDATED_NEW"
)

count=res['Attributes']['val']

print(count)

image.png

Recommended Posts

Creating numbering process using python in DynamoDB Local Numbering process
Translate using googletrans in Python
Using Python mode in Processing
A memo when creating a directed graph using Graphviz in Python
GUI programming in Python using Appjar
Try using LevelDB in Python (plyvel)
Using global variables in python functions
Let's see using input in python
Infinite product in Python (using functools)
Edit videos in Python using MoviePy
Handwriting recognition using KNN in Python
Try using Leap Motion in Python
Depth-first search using stack in Python
When using regular expressions in Python
Try using Amazon DynamoDB from Python
GUI creation in python using tkinter 2
I compared Node.js and Python in creating thumbnails using AWS Lambda
Mouse operation using Windows API in Python
Notes using cChardet and python3-chardet in Python 3.3.1.
GUI creation in python using tkinter part 1
(Bad) practice of using this in Python
Try using the Kraken API in Python
Using venv in Windows + Docker environment [Python]
[FX] Hit oanda-API in Python using Docker
Tweet using the Twitter API in Python
[Python] [Windows] Serial communication in Python using DLL
I tried using Bayesian Optimization in Python
Log in to Slack using requests in Python
Get Youtube data in Python using Youtube Data API
Process multiple lists with for in Python
Using physical constants in Python scipy.constants ~ constants e ~
Scraping a website using JavaScript in Python
Develop slack bot in python using chat.postMessage
Set up a local web server in 30 seconds using python 3's http.server
Write python modules in fortran using f2py
Draw a tree in Python 3 using graphviz
Notes for using python (pydev) in eclipse
Disease classification in Random Forest using Python
Download files in any format using Python
Creating Google Spreadsheet using Python / Google Data API
Parallel task execution using concurrent.futures in Python
Notes on using code formatter in Python
Meaning of using DI framework in Python
Template for creating command line applications in Python
Create a GIF file using Pillow in Python
Ubuntu18.04.05 Creating a python virtual environment in LTS
Email attachments using your gmail account in python.
Try using the BitFlyer Ligntning API in Python
Get image URL using Flickr API in Python
Notes on using dict in python [Competition Pro]
Let's judge emotions using Emotion API in Python
Perform entity analysis using spaCy / GiNZA in Python
View drug reviews using a list in Python
[Environment construction] Dependency analysis using CaboCha in Python 2.7
Pre-process the index in Python using Solr's ScriptUpdateProcessor
Load images from URLs using Pillow in Python 3
Create a MIDI file in Python using pretty_midi
Generate points only in Tokyo using python + shapely
Solve simultaneous equations in an instant using Python
Try using ChatWork API and Qiita API in Python
Try using the DropBox Core API in Python