Skip to content

Instantly share code, notes, and snippets.

@dpfrakes
Created March 8, 2019 06:35
Show Gist options
  • Save dpfrakes/eabc018acff09b8384f4e8ca0dfb5602 to your computer and use it in GitHub Desktop.
Save dpfrakes/eabc018acff09b8384f4e8ca0dfb5602 to your computer and use it in GitHub Desktop.
Run speedtest and upload results to AWS DynamoDB
import boto3
import speedtest
from decimal import Decimal
# Initialize variables
s = speedtest.Speedtest()
s.get_best_server()
# Run tests
s.download()
s.upload()
# Upload results to AWS
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.Table('speedtest_results')
response = table.put_item(
TableName='speedtest_results',
Item={
'Server ID': s.results.server['id'],
'Sponsor': s.results.server['sponsor'],
'Server Name': s.results.server['name'],
'Timestamp': s.results.timestamp,
'Distance': Decimal(str(s.results.server['d'])),
'Ping': Decimal(str(s.results.ping)),
'Download': Decimal(str(s.results.download)),
'Upload': Decimal(str(s.results.upload)),
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment