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)