AWS系统数据如何更新

1.注册aws账号:

https://aws.amazon.com/cn/premiumsupport/knowledge-center/create-and-activate-aws-account/

2.新建~/.aws/credentials

[default]
aws_access_key_id = xxx
aws_secret_access_key = xxx
region = us-east-2

3.python解析数据进行传输AWS

#!/usr/bin/python
#--*--coding:utf-8 --*--
import socket
import json
import boto3
from boto3.dynamodb.conditions import Key, Attr
from botocore.exceptions import ClientError

#recv data
#bind ip and port

ip_port=('172.27.28.25',9010)
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.bind(ip_port)

dynamodb = boto3.resource('dynamodb')

def table_create():
    try:
        table = dynamodb.create_table(
            TableName='points_test',
            KeySchema=[
                {
                    'AttributeName': 'num_frame',
                    'KeyType': 'HASH'
                },
                {
                    'AttributeName': 'num',
                    'KeyType': 'RANGE'
                }
            ],
            AttributeDefinitions=[
                {
                    'AttributeName': 'num_frame',
                    'AttributeType': 'N'
                },
                {
                    'AttributeName': 'num',
                    'AttributeType': 'N'
                },

            ],
            ProvisionedThroughput={
                'ReadCapacityUnits': 5,
                'WriteCapacityUnits': 5
            }
        )
        table.meta.client.get_waiter('table_exists').wait(TableName='points_test')
    except ClientError as ce:
        if ce.response['Error']['Code'] == 'ResourceInUseException':
            print("table already exists")
            pass

def table_get():
    return dynamodb.Table('points_test')

def item_put(num_frame,num,id,x,y,z,ref):
    table = table_get()
    table.put_item(
        Item={
                'num_frame': int(num_frame),
                'num': int(num),
                'id': int(id),
                'x': str(x),
                'y': str(y),
                'z': str(z),
                'ref': str(ref)
            }
    )

def item_get(num_frame,num):
    table = table_get()
    response = table.get_item(
        Key={
            'num_frame': str(num_frame),
            'num': str(num),
        }
    )
    item = response['Item']
    return item
def table_delete():
    table = table_get()
    table.delete()

if __name__ == '__main__':
    # table_delete()
    table_create()
    num_sum = 0
    while 1:
        data, addr = sock.recvfrom(102400)
        innovusion_data = json.loads(data.decode())
        print(innovusion_data)
        if ('frameId' in innovusion_data):
            frameId = innovusion_data['frameId']
        if ('points' in innovusion_data):
            points = innovusion_data['points']
        else:
            points = ""
        for i in range(len(points)):
            num=num_sum + i
            item_put(frameId,num,points[i]['id'],points[i]['x'],points[i]['y'],points[i]['z'],points[i]['ref'])
        num_sum=num_sum + len(points)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值