This template uses lambda written in python perform the operation on dynamodb
if insufficient, please contact Micro-letter correction (end of the article)
View dynamodb database needs to meet the following criteria
## have named wxz of nosql dynamodb database, to give the corresponding lambda iam and to dynamodb Have the corresponding permissions
1. Use lambda-python to view dynamodb data
import json
import boto3
import os
client = boto3.client('dynamodb')
def lambda_handler(event, context):
response = client.get_item(
TableName="wxz",
Key={
'server': {
"S":"wxz"
},
'num': {
"N":"12"
}
}
)
return response["Item"]["jc"]["S"]
2. Use lambda-python to update dynamodb data
import json
import boto3
import os
client = boto3.resource('dynamodb')
table = client.Table('wxy')
def lambda_handler(event, context):
response = table.update_item(
Key={
'server': "wxz",
'num': 12
},
UpdateExpression="set info=:r, plot=:p, actors=:a",
ExpressionAttributeValues={
':r': "10",
':p': "plot",
':a': "actors"
},
ReturnValues="UPDATED_NEW"
)
return response