generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added new aws lambda functions for new subscriptions and usage updates
- Loading branch information
Showing
9 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import json | ||
import os, re, base64 | ||
import boto3 | ||
|
||
def lambda_handler(event, context): | ||
|
||
mypage = page_router(event['httpMethod'],event['queryStringParameters'],event['body']) | ||
|
||
return mypage | ||
|
||
|
||
def page_router(httpmethod,querystring,formbody): | ||
|
||
if httpmethod == 'GET': | ||
htmlFile = open('subscription.html', 'r') | ||
htmlContent = htmlFile.read() | ||
return { | ||
'statusCode': 200, | ||
'headers': {"Content-Type":"text/html"}, | ||
'body': htmlContent | ||
} | ||
|
||
if httpmethod == 'POST': | ||
|
||
insert_record(formbody) | ||
|
||
htmlFile = open('thankyou.html', 'r') | ||
htmlContent = htmlFile.read() | ||
return { | ||
'statusCode': 200, | ||
'headers': {"Content-Type":"text/html"}, | ||
'body': htmlContent | ||
} | ||
|
||
def insert_record(formbody): | ||
|
||
formbody = formbody.replace("=", "' : '") | ||
formbody = formbody.replace("&", "', '") | ||
formbody = "INSERT INTO subscriptions value {'" + formbody + "'}" | ||
|
||
client = boto3.client('dynamodb') | ||
client.execute_statement(Statement= formbody) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
|
||
<h2>Subscription Form</h2> | ||
|
||
<form action="/dev" method="post"> | ||
<label for="providerId">ProviderId:</label><br> | ||
<input type="text" id="providerId" name="providerId" ><br> | ||
<label for="accountId">AccountId:</label><br> | ||
<input type="text" id="accountId" name="accountId" ><br> | ||
<label for="Tier Name">Tier Name:</label><br> | ||
<input type="text" id="tier" name="tier" ><br><br> | ||
<label for="Threshold">Threshold:</label><br> | ||
<input type="text" id="threshold" name="threshold" ><br><br> | ||
<label for="Threshold">Billing Cycle:</label><br> | ||
<input type="text" id="cycle" name="cycle" ><br><br> | ||
<label for="Threshold">Billing Start Date:</label><br> | ||
<input type="date" id="billStart" name="billStart" ><br><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
|
||
</body> | ||
</html> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
|
||
<h2>Thank you for your subscription!</h2> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
|
||
<h2>Error: usage threshold exceeded</h2> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import json | ||
import os, re, base64 | ||
import boto3 | ||
|
||
def lambda_handler(event, context): | ||
|
||
mypage = page_router(event['httpMethod'],event['queryStringParameters'],event['body']) | ||
|
||
return mypage | ||
|
||
|
||
def page_router(httpmethod,querystring,formbody): | ||
|
||
if httpmethod == 'GET': | ||
htmlFile = open('usage.html', 'r') | ||
htmlContent = htmlFile.read() | ||
return { | ||
'statusCode': 200, | ||
'headers': {"Content-Type":"text/html"}, | ||
'body': htmlContent | ||
} | ||
|
||
if httpmethod == 'POST': | ||
|
||
insert_record(formbody) | ||
|
||
htmlFile = open('status.html', 'r') | ||
htmlContent = htmlFile.read() | ||
return { | ||
'statusCode': 200, | ||
'headers': {"Content-Type":"text/html"}, | ||
'body': htmlContent | ||
} | ||
|
||
def insert_record(formbody): | ||
|
||
formbody = formbody.replace("=", "' : '") | ||
formbody = formbody.replace("&", "', '") | ||
formbody = "INSERT INTO usage value {'" + formbody + "'}" | ||
|
||
client = boto3.client('dynamodb') | ||
client.execute_statement(Statement= formbody) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
|
||
<h2>Success: Usage permitted</h2> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
|
||
<h2>Usage Form</h2> | ||
|
||
<form action="/dev" method="post"> | ||
<label for="providerId">ProviderId:</label><br> | ||
<input type="text" id="providerId" name="providerId" ><br> | ||
<label for="accountId">AccountId:</label><br> | ||
<input type="text" id="accountId" name="accountId" ><br> | ||
<label for="Tier Name">Usage:</label><br> | ||
<input type="text" id="usage" name="usage" ><br><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
|
||
</body> | ||
</html> |
Binary file not shown.