Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
lamda function to get all the lambda function and store them in a database
import json
import decimal
import urllib.request
import boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('AltCoinHistory')
def lambda_handler(event, context):
url = ''
response = urllib.request.urlopen(url).read().decode('utf-8')
cryptos = json.loads(response, parse_float = decimal.Decimal)
for crypto in cryptos:
symbol = (crypto['symbol'])
price_usd = decimal.Decimal(crypto['price_usd'] or 0)
price_btc = decimal.Decimal(crypto['price_btc'] or 0)
a24h_volume_usd = decimal.Decimal(crypto['24h_volume_usd'] or 0)
percent_change_1h = decimal.Decimal(crypto['percent_change_1h'] or 0)
percent_change_24h = decimal.Decimal(crypto['percent_change_24h'] or 0)
percent_change_7d = decimal.Decimal(crypto['percent_change_7d'] or 0)
last_updated = int(crypto['last_updated'] or 0)
'symbol': symbol,
'last_updated': last_updated,
'price_usd': price_usd,
'price_btc': price_btc,
'24h_volume_usd': a24h_volume_usd,
'percent_change_1h': percent_change_1h,
'percent_change_24h': percent_change_24h,
'percent_change_7d': percent_change_7d,
return "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.